Cascading Combobox

Topics: Getting Started
Sep 22, 2013 at 11:47 PM
Can someone please help me with a cascading combo box issue. Here's the markup
            <DataGrid x:Name="Mappings"
                  AutoGenerateColumns="False" 
                  HeadersVisibility="Column" 
                  CanUserReorderColumns="False" 
                  CanUserResizeColumns="False" 
                  CanUserSortColumns="False" 
                  ColumnWidth="SizeToCells"
                  SelectedItem="SelectedMapping"
                  Margin="5" MinWidth="500" DockPanel.Dock="Bottom">
                <DataGrid.Columns>
                    <DataGridTemplateColumn Header="IOS" MinWidth="120">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Ios}" MinHeight="26" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SourceIOSNames}"
                                  SelectedItem="{Binding Ios, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" 
                                  cal:Message.Attach="[Event SelectionChanged] = [Action UpdateSourceAccounts()]"  />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTemplateColumn Header="Account" MinWidth="120">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Account}" MinHeight="26" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.SourceAccounts}"
                                  SelectedItem="{Binding Account, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsSynchronizedWithCurrentItem="True" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
Here's some of the code
        public BindableCollection<IAccountMapping> Mappings { get; private set; }

        public IAccountMapping SelectedMapping
        {
            get { return _selectedMapping; }
            set
            {
                _selectedMapping = value;
                NotifyOfPropertyChange(() => SelectedMapping);
            }
        }

        public BindableCollection<string> SourceAccounts
        {
            get; set;
        }

        public BindableCollection<string> SourceIOSNames
        {
            get
            {
                return new BindableCollection<string> { "TEST1", "TEST2" };
            }
        }
The SourceAccounts is populated via the UpdateSourceAccounts method (not shown) which is getting correctly called when the IOS value gets changed. the UpdateSourceAccounts method also tries to modify the Account value but this value does not appear to change (even the debugger shows it hasn't changed despite being set explicitly to String.Empty).

What I want to happen is that when the value in the first combo is changed, the value in the second combo gets blanked out. This must be done via the ViewModel bindings.

Any assistance appreciated.

Regards
Alan