How to 2-way associate a <enum, bool> dictionary with a ListView column in WPF?
I have a type like this:
public class EffectViewModel
{
public string Name { get; set; }
public string Category { get; set; }
public Dictionary<ShaderType, bool> ShaderSupport { get; set; }
}
.Nameand are .Categoryalready tied to two separate columns, but not in the dictionary ShaderSupport.
I cannot figure out how to use a two-way dictionary for a separate column for each ShaderType. I do not know if this number of columns can be done dynamically, but I hardcoded them in xaml, so:
<GridViewColumn Width="60" Header="GPU" >
<GridViewColumn Width="60" Header="Pixel" >
...
But now stuck on the connecting part. Any ideas?
+5
2 answers
<ItemsControl Grid.IsSharedSizeScope="True" ItemsSource="{Binding AllEffects}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="NameColumn" />
<ColumnDefinition Width="Auto" SharedSizeGroup="CategoryColumn" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Category}" Grid.Column="1" />
</Grid>
<ItemsControl ItemsSource="{Binding ShaderSupport}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>
<CheckBox Grid.Row="1" IsChecked="{Binding Value, Mode=OneWay}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
. TwoWay, , KeyValuePair Value , , TwoWay.
, EffectVM .
+3
- IEnumerable, . , ,
<ListView ItemsSource="{Binding ShaderSupport}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="60" Header="Key" DisplayMemberBinding="{Binding Key}" />
<GridViewColumn Width="60" Header="Value" DisplayMemberBinding="{Binding Value}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
+1