私が作業しているアプリケーションの1つで、このコードを見つけました-
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>