Purpose of using FrameworkElementFactory

In one of the applications I work, I 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 one is MatrixCellTemplateused to set CellTemplatecustom DataGridTemplateColumn(later added to the collection DataGrid.Columns), like this -

<DataGridTemplateColumn.CellTemplate>
    <Matrix:MatrixCellTemplate />
</DataGridTemplateColumn.CellTemplate>

I'm not sure what the advantage of using this is FrameworkElementFactoryand what problem I may encounter if I directly use MatrixCellContaineras a cell template -

<DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <Matrix:MatrixCellContainer>
        </Matrix:MatrixCellContainer>
    </DataTemplate>
    <!--<Matrix:MatrixCellTemplate />-->
</DataGridTemplateColumn.CellTemplate>
+5
source share
1 answer

, , , XAML, , ( , , - ).

FrameworkElementFactory :

, FrameworkTemplate, ControlTemplate DataTemplate; . XAML Load XamlReader.

+8

All Articles