0
votes

I have a WPF application and am using the MVVM pattern. I have a ComboBox whose value is used as a parameter for the ItemsSource of a DataGrid. I created a public property for the ComboBox value and public ObservableCollection for the DataGrid. When the public property bound to the ComboBox changes, I use an EventHandler to change the ObservableCollection and the DataGrid updates.

I'm refactoring the code because that ComboBox will be used by different parts of the application. So, I took this single view and created 2 UserControls, 1 for the ComboBox and 1 for the DataGrid. I then created a base ViewModel that inherits the INotifyPropertyChange class, which is used by the ComboBox user control. I created a second ViewModel that inherits the base ViewModel, which is used by the DataGrid control.

Here's my problem, when the ComboBox changes, I don't know how the EventHandler communicates with the ObservableCollection. When they were in the same ViewModel, I simply passed the name of the ObservableCollection.

How do I change the ObservableCollection property in a ViewModel that is inheriting the ViewModel where the EventHandler resides?

1
can you just raise it explicitly inside the Setter of the OC? .. RaisePropertyChanged("PropertyToRaise");d.moncada

1 Answers

0
votes

So you have two ViewModels derived from same base model? I would simply use one ModelView for both Usercontrols. I don't know if this is against MVVM Pattern, but for me it would be the easiest solution.