The DataGrid is an editable list control that can be used as an editing control for a column. For example, you can use the ComboBox control to edit a column, in this case, we need to set the ComboBox control drop-down list items first. How can we do this in Silverlight?
First, define the XAML as follows:
<Data: DataGrid grid. Row = "0" X: Name = "gridvariables" rowheight = "20" autogeneratecolumns = "false" borderthickness = "1, 1, 1">
<Data: DataGrid. Columns>
<Data: datagridtemplatecolumn header = "type" width = "120">
<Data: datagridtemplatecolumn. celltemplate>
<Datatemplate>
<Textblock text = "{binding type}"/>
</Datatemplate>
</Data: datagridtemplatecolumn. celltemplate>
<Data: datagridtemplatecolumn. celleditingtemplate>
<Datatemplate>
<ComboBox>
</ComboBox>
</Datatemplate>
</Data: datagridtemplatecolumn. celleditingtemplate>
</Data: datagridtemplatecolumn>
</Data: DataGrid. Columns>
</Data: DataGrid>
Second, you need to define a class and use a property of the class to improve the option data source, as shown below:
Public class workflowvariabletypes
{
Public list <workflowvariabletype> workflowvariabletypelist
{
Get
{
List <workflowvariabletype> types = new list <workflowvariabletype> ();
For (INT I = 0; I <14; I ++)
{
Types. Add (New workflowvariabletype {type = (variabletype) I });
}
Return types;
}
}
}
Then, we can declare an instance of this class through the user control resource, as follows:
<Usercontrol. Resources>
<Local: workflowvariabletypes X: Key = "workflowvariabletypes"/>
</Usercontrol. Resources>
Finally, the resource is used as follows:
<Data: datagridtemplatecolumn. celleditingtemplate>
<Datatemplate>
<ComboBox itemssource = "{binding workflowvariabletypelist, source = {staticresource workflowvariabletypes}">
</ComboBox>
</Datatemplate>
</Data: datagridtemplatecolumn. celleditingtemplate>
This process is similar to formatting the column data in the DataGrid, and we can also get an experience that the resource of the user control is very powerful, it can be used to reference static things (images, styles, etc.) or dynamic things ( Code , Class ).