在我正在工作的一个应用程序中,我发现了这段代码 -
public class MatrixCellTemplate : ColumnDataTemplate<MatrixCellContainer>
{
}
public class ColumnDataTemplate<T> : DataTemplate where T : FrameworkElement
{
public ColumnDataTemplate()
{
FrameworkElementFactory factory = new FrameworkElementFactory(typeof(T));
VisualTree = factory;
}
}
这MatrixCellTemplate
用于设置这样CellTemplate
的自定义DataGridTemplateColumn
(后来添加到DataGrid.Columns
集合中) -
<DataGridTemplateColumn.CellTemplate>
<Matrix:MatrixCellTemplate />
</DataGridTemplateColumn.CellTemplate>
我不确定使用它FrameworkElementFactory
有什么好处,如果我直接MatrixCellContainer
用作单元格模板会遇到什么问题 -
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Matrix:MatrixCellContainer>
</Matrix:MatrixCellContainer>
</DataTemplate>
<!--<Matrix:MatrixCellTemplate />-->
</DataGridTemplateColumn.CellTemplate>