0

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"); Commented Apr 3, 2014 at 2:37

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.