silverlight - How to bind to stackpanel children? -
silverlight - How to bind to stackpanel children? -
i define stackpanel 4 textblock within , define object holds 4 strings properties.
class { public string str1; public string str2; public string str3; public string str4; } <stackpanel> <textblock x:name="txt1" /> <textblock x:name="txt2" /> <textblock x:name="txt3" /> <textblock x:name="txt4" /> </stackpanel>
i want define binding between object instance of class , stackpanel textblock.text
how can ?
to bind str1-4 have get/set properties @ minimum (and notify properties if alter after view connected instance of class a).
class { public string str1 { get; set; } public string str2 { get; set; } public string str3 { get; set; } public string str4 { get; set; } } <stackpanel> <textblock x:name="txt1" text={binding str1} /> <textblock x:name="txt2" text={binding str2} /> <textblock x:name="txt3" text={binding str3} /> <textblock x:name="txt4" text={binding str4} /> </stackpanel>
i not know class exists, or if using mvvm (i guessing not), @ minimum in constructor of view need set datacontext of view (or stack panel) instance of "a".
e.g.
public myview() { initializecomponent(); this.datacontext = myainstance; }
or if want target stackpanel name stackpanel , set datacontext:
<stackpanel x:name="mystackpanel"> public myview() { initializecomponent(); this.mystackpanel.datacontext = myainstance; }
silverlight
Comments
Post a Comment