In one of the application I am working I have found this code -
public class MatrixCellTemplate : ColumnDataTemplate<MatrixCellContainer>
{
}
public class ColumnDataTemplate<T> : DataTemplate where T : FrameworkElement
{
public ColumnDataTemplate()
{
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(T));
VisualTree = factory;
}
}
This MatrixCellTemplate
is used to set the CellTemplate
of a custom DataGridTemplateColumn
(later added to DataGrid.Columns
collection) like this -
<DataGridTemplateColumn.CellTemplate>
<Matrix:MatrixCellTemplate />
</DataGridTemplateColumn.CellTemplate>
I am not sure what is the benefit of using this FrameworkElementFactory
and what problem I can face if I directly use MatrixCellContainer
as cell template -
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Matrix:MatrixCellContainer>
</Matrix:MatrixCellContainer>
</DataTemplate>
<!--<Matrix:MatrixCellTemplate />-->
</DataGridTemplateColumn.CellTemplate>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…