WPF cascading combo

I use LINQ to SQL and the MVVM pattern in my application, where I retrieve my data with the following query:

internal ObservableCollection<INVCategory> GetCategoryList()
{
     DataLoadOptions dataLoadOptions = new DataLoadOptions();
     dataLoadOptions.LoadWith<INVCategory>(t => t.INVSubCategories);
     this.Context.LoadOptions = dataLoadOptions;

     var categories = from category in this.Context.INVCategories
                      orderby category.CatgeoryId descending
                      select category;
     return new ObservableCollection<INVCategory>(categories.ToList());
}

And my XAML code for the parent (Category) combo:

<ComboBox Grid.Column="1" Grid.Row="0" HorizontalAlignment="Stretch"                           VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="0" x:Name="categoryComboBox"      
ItemsSource="{Binding CategoryList}" IsEditable="True" DisplayMemberPath="CategoryName"  SelectedValuePath="CatgeoryId" SelectedItem="{Binding CategoryList, Mode=TwoWay}" SelectedValue="{Binding Path=CurrentEntity.CategoryId, Mode=TwoWay}" >
</ComboBox>

for the child (subcategory) combo I use:

<ComboBox Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,2,10,2" TabIndex="1"
ItemsSource="{Binding SelectedItem, ElementName=categoryComboBox, Mode=OneWay}" 
DisplayMemberPath="SubCategoryName" SelectedValuePath="SubCategoryId"
SelectedItem="{Binding INVSubCategories, Mode=TwoWay}" >
</ComboBox>

But my child combos are not filled during form loading, and the parent combo selection has changed, although my parent combos are filled. I can’t understand why my daughter combo is not working based on the parent combos of the selected item, please help me.

+3
source share

Source: https://habr.com/ru/post/1745222/


All Articles