c# - Access properties of elements defined in ControlTemplate in xaml -


in xaml have put 10 items defined as:

<stackpanel orientation="horizontal" grid.row="0" grid.column="1">   <textbox width="100"            datacontext="{staticresource dataprovider}"            text="{binding xpath='block[@id=2]/items/item[@id=1]/@value'}"/>   <combobox margin="5"              datacontext="{staticresource dataprovider}"             selectedvaluepath="tag"             selectedvalue="{binding xpath='block[@id=2]/items/item[@id=2]/@value'}">     <comboboxitem content="group" tag="6" />     <comboboxitem content="private" tag="5" />   </combobox>               <textbox width="200"            datacontext="{staticresource dataprovider}"            text="{binding xpath='block[@id=2]/items/item[@id=4]/@value'}"/> </stackpanel> 

so, instead of repeat many times, thought use controltemplate this:

<datatemplate.resources>   <controltemplate x:key="addressitemtemplate">     <stackpanel orientation="horizontal">       <textbox name="address" width="200"/>       <combobox name="type">         <comboboxitem content="group" tag="6" />         <comboboxitem content="private" tag="5" />       </combobox>       <textbox name="description" width="200"/>     </stackpanel>   </controltemplate>       </datatemplate.resources> 

now when use it...

<control grid.row="0" grid.column="1" template="{staticresource addressitemtemplate}" /> <control grid.row="1" grid.column="1" template="{staticresource addressitemtemplate}" /> <control grid.row="2" grid.column="1" template="{staticresource addressitemtemplate}" /> 

.. since xpath binding property different each item (the item[@id] changes always), need way access textbox.text, combobox.selectedvaluepath , combobox.selectedvalue property when create 'control'.

is there way it?

this common question in wpf. can access these elements if named control control this:

textbox textbox = (textbox)control.template.findname("address", control);  combobox combobox = (combobox)control.template.findname("type", control); 

i trust can work rest out yourself.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -