a) How to bind an enumeration to a Combo Editor in a grid column
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type System:Enum}" x:Key="EnumKey">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Model:EnumType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource ResourceKey=EnumKey}}" />
b) How to bind list of objects to a Combo Editor in a grid column
1) Grid Column Type a simple data type
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.ListOfCustomObj}" />
<Setter Property="DisplayMemberPath" Value="NameOfPropertyToDisplay" />
<Setter Property="ValuePath" Value="PropertyForValue" />
2) Grid Column Type a custom data type
<Setter Property="DisplayMemberPath" Value="NameOfPropertyToDisplay" />
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.ListOfCustomObj}" />
Note: These above couple of line may not be sufficient as combo box may be displaying type instead of item, in which case custom Data Type needs to override Equals method
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type System:Enum}" x:Key="EnumKey">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Model:EnumType" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource ResourceKey=EnumKey}}" />
b) How to bind list of objects to a Combo Editor in a grid column
1) Grid Column Type a simple data type
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.ListOfCustomObj}" />
<Setter Property="DisplayMemberPath" Value="NameOfPropertyToDisplay" />
<Setter Property="ValuePath" Value="PropertyForValue" />
2) Grid Column Type a custom data type
<Setter Property="DisplayMemberPath" Value="NameOfPropertyToDisplay" />
<Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=DataContext.ListOfCustomObj}" />
Note: These above couple of line may not be sufficient as combo box may be displaying type instead of item, in which case custom Data Type needs to override Equals method
No comments:
Post a Comment