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.v24.2.dll
NuGet Package: DevExpress.Wpf.Core
Declaration
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:
- Creates the TreeListView instance for the first GridControl.
- Creates the TreeListView instance for the second GridControl and deletes the instance created for the first GridControl.
- The first GridControl‘s
View
property isnull
. As a result, the GridControl displays its default view (TableView).
<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:
<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