how to get cell template control values
halo experts,
below code bined cell template in datagrid. consider datagrid itemsource binded collection of 5 objects. according below code, 5 text box , 5 date picker controls generated inside datagrid. how can each controls?(5 text box values)
<my:datagrid x:name="targetdatagrid" autogeneratecolumns="false" > <my:datagrid.columns> <my:datagridtemplatecolumn header="birthday"> <my:datagridtemplatecolumn.celltemplate> <datatemplate> <textblock text="{binding birthday, converter={staticresource dateconverter}}" fontfamily="trebuchet ms" fontsize="11" margin="5,4,5,4"/> </datatemplate> </my:datagridtemplatecolumn.celltemplate> <my:datagridtemplatecolumn.celleditingtemplate> <datatemplate> <datepicker selecteddate="{binding birthday, mode=twoway}" /> </datatemplate> </my:datagridtemplatecolumn.celleditingtemplate> </my:datagridtemplatecolumn> </my:datagrid.columns> </my:datagrid>
hi,
if using sl4, there useful extension methods use.
var = dg.getvisualdescendants().where(t => t.gettype().equals(typeof(textblock)));
the above line textblock inside datagrid.
if using sl3 , may need write generic method traverse through dg's visual tree , want.
list<frameworkelement> result = new list<frameworkelement>();
public void getchildobject<t>(frameworkelement obj) t : frameworkelement {
(int = 0; < visualtreehelper.getchildrencount(obj); i++) {
frameworkelement c = visualtreehelper.getchild(obj, i) frameworkelement;
if (c.gettype().equals(typeof(t)))
{
result.add(c);
}
getchildobject<t>(c);
}
}
best regards
Silverlight > Programming Silverlight with .NET – General
Comments
Post a Comment