Skip to main content
All docs
V25.1
  • ValueFactoryExtension Class

    Allows you to create unshared instances of objects in styles. The extension creates these instances for each element that uses the style.

    Namespace: DevExpress.Mvvm.UI

    Assembly: DevExpress.Xpf.Core.v25.1.dll

    NuGet Package: DevExpress.Wpf.Core

    Declaration

    public class ValueFactoryExtension :
        MarkupExtension

    Remarks

    Code samples in this topic contain two GridControls. Their View property is defined in the gridStyle resource.

    If you create a TreeListView instance in a style without the ValueFactoryExtension, WPF does the following:

    1. Creates the TreeListView instance for the first GridControl.
    2. Creates the TreeListView instance for the second GridControl and deletes the instance created for the first GridControl.
    3. The first GridControl‘s View property is null. As a result, the GridControl displays its default view (TableView).

    Define a View Without the ValueFactoryExtension

    <Window.Resources>
        <Style TargetType="dxg:GridControl" x:Key="gridStyle">
            <Setter Property="ItemsSource" Value="{Binding Persons}"/>
            <Setter Property="AutoGenerateColumns" Value="AddNew"/>
            <Setter Property="EnableSmartColumnsGeneration" Value="True"/>
            <Setter Property="View">
                <Setter.Value>
                    <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" 
                                      AutoWidth="True" AutoExpandAllNodes="True"/>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <dxg:GridControl Style="{StaticResource gridStyle}"/>
        <dxg:GridControl Style="{StaticResource gridStyle}" Grid.Row="1"/>
    </Grid>
    

    The ValueFactoryExtension creates object instances for all elements that use the style:

    Use the ValueFactoryExtension to Define a View

    <Window.Resources>
        <Style TargetType="dxg:GridControl" x:Key="gridStyle">
            <Setter Property="ItemsSource" Value="{Binding Persons}"/>
            <Setter Property="AutoGenerateColumns" Value="AddNew"/>
            <Setter Property="EnableSmartColumnsGeneration" Value="True"/>
            <Setter Property="View">
                <Setter.Value>
                    <dxmvvm:ValueFactory>
                        <DataTemplate>
                            <dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" 
                                              AutoWidth="True" AutoExpandAllNodes="True"/>
                        </DataTemplate>
                    </dxmvvm:ValueFactory>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <dxg:GridControl Style="{StaticResource gridStyle}"/>
        <dxg:GridControl Style="{StaticResource gridStyle}" Grid.Row="1"/>
    </Grid>
    

    Inheritance

    Object
    MarkupExtension
    ValueFactoryExtension
    See Also