c# - XamarinForms TemplateBinding Equivalent -
i'm trying create mutual custom command in xamarinforms pcl project equivalent of usercontrol in windows 8/rt.
here's have far.
first created bindable property in command inherits contentview:
public static readonly bindableproperty titleproperty = bindableproperty.create<mycustomcontrol, string> ( p => p.title, defaultvalue: "no title", defaultbindingmode: bindingmode.twoway, validatevalue: null, propertychanged: (bindableobject, oldvalue, newvalue) => { if (bindableobject != null) { } logger.instance.writeline ("title property changed: oldvalue = " + oldvalue + " , newvalue = " + newvalue); }); public string title { { homecoming (string)getvalue (titleproperty); } set { setvalue (titleproperty, value); } }
then want utilize in label in xaml such:
<label text="{templatebinding title}" />
however, templatebinding markupextension doesn't exist xamlparseexception.
i can think of workaround naming label x:name="mylabel" , changing text value in propertychanged delegate newvalue, there improve way that?
i not require custom renderers command , want in xaml if possible. in advance!
update: pete answered it. utilize {binding } , set bindingcontext properly.
here's how got work.
var pagecontent = new customcontrol (); pagecontent.setbinding (customcontrol.titleproperty, new binding(path: "title")); pagecontent.bindingcontext = new {title = "this title that's databound!"};
doesn't default value in bindableproperty works though..
i'm not sure if helps perhaps?
<label text="{binding title}"/>
remembering set bindingcontext
also?
c# xaml xamarin xamarin-studio xamarin.forms
No comments:
Post a Comment