What I’m trying to do seems very simple, but for some reason it feels clunky so I think I’m doing something wrong.
All I want to do is have a few dropdowns, and these dropdowns change settings. They are saved when they are changed.
There is a dropdown that controls the content that is shown on the WPF window. When this dropdown changes, the settings inside the other dropdowns change to new selections.
My problem is when I fill in the values for all the dropdowns when the window loads, it fires the events selectionchanged for all the dropdowns.
So instead of having null checks in my every single event (which is what I have now) I want a better solution.
These dropdowns will NEVER not have values. They are not static either. They are calculated at run-time from a data source. Even static values appear to fire the events.
Some of the dropdowns have fixed values across all the values in the dropdown that controls all the others. This means they are calculated at run-time during start up and never change.
I do not want to have to bind the events in the code behind.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// This triggers the combobox selectionchanged
// The selection changed event sets the values of other dropdowns
// The event will not succeed because the values in those dropdowns
// are not populated
FillProjectList();
}
How about stop using the one drop-down to control other’s selected items and instead, have the ViewModel (or your binding class) control that.
Each drop-down already has it’s source, add binding to selected item (that should Mode two-way by default, I think)
Then when the ViewModel’s SelectedConrolingItem property changes, update/set the other selected items (SelectedProject, etc..) in the property setter