How to set DataGridCell's template in WpfToolkit's DataGrid?
Question
Is it possible to set DataGridCell's template when using WpfToolkit's DataGrid? Or is it possible to set style property for a single cell at the time?
I know that there is a TemplateColumn class which lets the user set templates for displaying and editing cell's data but that's not what I'm looking for.
I need to display two-dimensional arrays with DataGrid and style single cells according to their values. I'd also like to use VM-M-V model and create ViewModel wrapper for each cell which would have an IsSelected property binded to cell's IsSelected property so I could easily iterate over my data source for selected cell's instead of using DataGrid's more row oriented API.
Solution
Here's a couple of ways I found to get started:
How to populate a WPF grid based on a 2-dimensional array
Another option is the following:
<List<string>> tempList = new List<List<string>> {
new List<string> { "vince", "elizabeth", "brian", "mark" },
new List<string> { "vince2", "elizabeth2", "brian2", "mark2" },
new List<string> { "vince3", "elizabeth3", "brian3", "mark3" },
new List<string> { "vince4", "elizabeth3", "brian3", "mark4" },
};
for(int i=0; i<tempList[0].Count; i++) {
DataGrid_Standard.Columns.Add(new DataGridTextColumn {
Header = i,
DataFieldBinding = new Binding("[" + i + "]")
});
}
DataGrid_Standard.ItemsSource = tempList;