wpf-devexpress-dot-mvvm-dot-ui-a2d730e0.md
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.2.dll
NuGet Package : DevExpress.Wpf.Core
public class ValueFactoryExtension :
MarkupExtension
Public Class ValueFactoryExtension
Inherits MarkupExtension
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:
View property is null. 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>
Object MarkupExtension ValueFactoryExtension
See Also