0

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>

Screen Capture

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

  1. 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 outer Grid's ActualWidth, but that grid's ActualWidth property always returns 0 (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 the Grid control, not the GridView 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?
Community
  • 1
  • 1
turkinator
  • 905
  • 9
  • 25
  • 2
    I can answer to your first question. The problem is in your cs code. you are puting the same collection into *DBPriorities* property for all objects of *Mappings* collection... You must create new instance for each object – Amine May 03 '16 at 22:28
  • You can share cs code if it's not clear – Amine May 03 '16 at 22:33
  • Thank you @Amine .One down. :-) – turkinator May 03 '16 at 22:58
  • Anime - If you wouldn't mind taking a look at a followup question - http://stackoverflow.com/questions/37018071/wpf-binding-resourcedictionary-source-to-a-resourcedictionary-property-of-the Thank you. – turkinator May 04 '16 at 04:47
  • Try this – Archana May 04 '16 at 05:51

0 Answers0