xamarin.forms - How to keep BaseView's two-way bindable Properties and event when using CustomRenderer : ViewRenderer<A, B> -
first wanna use custom uitextfield named jvfloatlabeledentry in x.f. here reference custom uitextfield https://github.com/gshackles/jvfloatsharp
so here steps:
xf side: 1. jvfloatlabeledentry.cs
public class jvfloatlabeledentry : entry { public color floatinglabelcolor { get; private set;} public color floatinglabelactivecolor { get; private set;} public jvfloatlabeledentry () : base() { widthrequest = 300; heightrequest = 44; floatinglabelcolor = color.gray; floatinglabelactivecolor = color.black; } }
ios side: 2. jvfloatlabeledtextfield.cs custom uitextfield wanna use. can find file in github https://github.com/gshackles/jvfloatsharp 3. jvfloatlabeledentryrenderer.cs customrenderer creates brand new jvfloatlabeledtextfield , sets nativecontrol
[assembly: exportrenderer (typeof (jvfloatlabeledentry), typeof (jvfloatlabeledentryrenderer))] namespace dutyfreecollection.ios { public class jvfloatlabeledentryrenderer : viewrenderer<jvfloatlabeledentry, jvfloatlabeledtextfield> { public jvfloatlabeledentryrenderer () {} protected override void onelementchanged (elementchangedeventargs<jvfloatlabeledentry> e) { base.onelementchanged (e); var jfflentry = e.newelement; if (jfflentry != null) { const float jvfieldhmargin = 10.0f; const float jvfieldfontsize = 16.0f; const float jvfieldfloatinglabelfontsize = 11.0f; // whenever use jvfloatlabeledentry on xf side, newview instead used var newview = new jvfloatlabeledtextfield ( new rectanglef(jvfieldhmargin, 0, (float)jfflentry.widthrequest, (float)jfflentry.heightrequest)) { text = jfflentry.text, placeholder = jfflentry.placeholder, font = uifont.systemfontofsize (jvfieldfontsize), clearbuttonmode = uitextfieldviewmode.whileediting, floatinglabelfont = uifont.boldsystemfontofsize (jvfieldfloatinglabelfontsize), floatinglabeltextcolor = jfflentry.floatinglabelcolor.touicolor(), floatinglabelactivetextcolor = jfflentry.floatinglabelactivecolor.touicolor(), borderstyle = uitextborderstyle.roundedrect }; setnativecontrol (newview); } } } }
my problem after set new jvfloatlabeledtextfield native control, members event textchanged , properties textproperty of entry on xf side gone. i.e.
jvfloatlabeledentry floatlabeledentry = new jvfloatlabeledentry(); floatlabeledentry.textchanged += (object sender, textchangedeventargs e) => { // never comes here, event textchanged of jvfloatlabeledentry gone, why? since jvfloatlabeledentry derived entry, why event textchanged gone? };
same thing happens other members of custom entry,
floatlabeledentry.setbinding(jvfloatlabeledentry.textproperty, "any_binding_field"); // two-way binding gone well.
i reached bottle neck, please tell me how keep jvfloatlabeledentry(customentry)'s base class entry's properties binding , eventhandlers. thank much.
if understand question correctly problem in way initialize ios native control - there no events you're listening on native side (including lack of bindings), you're initializing native control in fire-and-forget manner.
you need add code translate native events forms events. i'm not familiar enough custom control you're using, in renderer after init control you'd need hook events, along lines:
newview.textchangedevent+=(s,e) => jfflentry.ontextchanged(jffl, new textchangedeventargs(e.newtext);
the code above made should give idea do, if not - ask what's unclear
Comments
Post a Comment