0

I am developing a WPF application for displaying data in a plot. I have a UserControl that acts as a View. In its codebehind file, I have created an ObservableCollection<MyViewModel>. These are displayed in the DataGrid.

    public partial class TagGridView : UserControl
        {
            private TagGridViewModel _tagGridViewModel = new TagGridViewModel();

I have another UserControl, acting as another View that has a Button in it. The button opens a file dialog. I would like to be able to use the result of the file dialog operation from the separate view to add an item to the ObservableCollection<MyViewModel>, thus updating the grid.

Am I supposed to have a MainViewModel in every view containing a static instance of all other ViewModels that are required? How can I access the collection?

  • No. No. No. No. Don't create ViewModels for your UserControls. No. Read this http://stackoverflow.com/questions/28175338/hair-loss-and-mvvm-user-controls/28175766#28175766 –  Feb 06 '15 at 16:44
  • You can pass the collection to the new view when it is getting created and use it there. There are many ways of doing it. As you said Static or Single instance viewmodel is another approach. – Ayyappan Subramanian Feb 06 '15 at 16:45

0 Answers0