1
I’ve been trying to figure out how to synchronize a combobox with another one for some time. I’m looking to synchronize comboboxes at runtime. When the user selects a category in the combobox, depending on his choice, the combobox subcategory will show the subcategories of the selected category.
I am using WPF and C# with Entityframework 6.
In my application, I can read in my Viewmodel what was selected in the combobox in View. I wanted to know how to update, dynamically, a combobox depeded from what was selected in another combobox, using the MVVM standard. Follow excerpts from the code:
<ComboBox Name="cbCategoria"
ItemsSource="{Binding NomeCategorias}"
SelectedItem="{Binding NomeCategoria}"
Width="175" />
<ComboBox Name="cbSubCtg"
ItemsSource="{Binding NomeSubCategorias}"
SelectedItem="{Binding NomeSubCategoria}"
Width="175" />
As you can see, in my Viewmodel I keep what I read in Comobobox cbCategoria
in the variable NomeCategoria
.
From now on I appreciate any help.
I’m using this site to get an idea (http://www.dotnetperls.com/combobox-wpf), but I’m not sure how to get what was read on the first combobox .
– Iago Frota
It’s been a while since I’ve worked with WPF, you’ve tried to use the event
SelectionChanged
combo? I’m writing an answer that uses it, but I don’t know if that’s your problem.– Jéf Bueno
@jbueno I even got an example saying this, but I think it doesn’t look cool, because, in my head, I’ll have to put logic in the Behind code of the view. I think the solution to my problem will use yes the
SelectionChanged
, but it won’t be just that. I think... rsrsrs– Iago Frota
My problem is being on how to update this at runtime.
– Iago Frota