c# - Access Elements in DataTemplate -


i have following item template (i tried strip non relevant stuff):

<s:surfacewindow.resources>     <resourcedictionary>         <style targettype="{x:type s:surfacelistbox}">             <setter property="itemtemplate">                 <datatemplate datatype="{x:type local:myclass}"> //my own class                     <s:surfacebutton>                         <textblock text="{binding name}">        //name string in own class //and close tags 

the idea listbox contain buttons displaying words on it.

further down, have surfacelistbox using above resource. add in item by:

mylistbox.items.add(new myclass("my name")); 

and add button listbox nicely, button displaying "my name".

now need change "my name" string.

how access textblock?

i have tried googling solutions access items in datatemplate require visualtreehelper.getchildrencount via findvisualchild, returns 0 me doesn't work.

the simple , right way achieve using databinding.

update textblock xaml textblock can update whenever backend name property changes

<textblock text="{binding name, updatesourcetrigger=propertychanged}"> 

in myclass implement inotifypropertychanged. whenever wish change text call propertychanged event.

public name {         {         return _name;     }     set     {         _name = value;         propertychanged("name");     } } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -