I have the following View:
<UserControl x:Name="userControl" x:Class="CallTypePriorityMapping.MapperView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CallTypePriorityMapping.Views"
xmlns:ViewModels="clr-namespace:CallTypePriorityMapping.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<ViewModels:CallTypeMappingsPresenter />
</UserControl.DataContext>
<Grid HorizontalAlignment="Stretch" x:Name="MappingGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*" x:Name="Col1"/>
<ColumnDefinition Width="0.5*" x:Name="Col2"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="259*"/>
</Grid.RowDefinitions>
<Button x:Name="button" Content="+ New Mapping" Margin="10" Grid.Column="1" Command="{Binding AddMapping, UpdateSourceTrigger=PropertyChanged}"/>
<ListView x:Name="listView" Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Mappings, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Header="Call Type" x:Name="callTypeCol">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Margin="0" HorizontalAlignment="Stretch" x:Name="CallTypeName" ItemsSource="{Binding DBCallTypes, ElementName=userControl}" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Value" SelectedItem="{Binding CallType.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Priority">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox HorizontalAlignment="Stretch" x:Name="PriorityName" ItemsSource="{Binding DBPriorities, ElementName=userControl}" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Value" SelectedItem="{Binding Priority, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</UserControl>
This, for the most part, works, but I have a couple issues:
1. Changing either column's value on a single row also changes that value in all other rows. Solved - See below comment from @Amine
- I cannot get the columns & comboboxes to auto-size (to equal portions of the fill width). The
Width
property on GridView & GridView Columns will not accept*
(or a percentage). I've tried Binding to the outerGrid
'sActualWidth
, but that grid'sActualWidth
property always returns0
(even after hooking into the re-size event and setting a dependency property, then re-sizing and walking the code in debug). I've been searching and reading similar posts all over the web, but see a lot of people using Code-Behind or GridColumnDefinitions (which seems to only exist in theGrid
control, not theGridView
control). I've also found many ways to solve this by replacing the GridView with another class, but have found no XAML-only solution using the GridView class. Am I missing something?