0

How to make an aggregate View Model in MVVM? basically I wanna add multiple ViewModels together. Here is what I have tried.

using System;
using System.Windows.Input;
using Microsoft.VisualStudio.Shell.Interop;

namespace NavigationAssistant
{
    internal class NavigationAssistantViewModel
    {
        private IVsUIShell uiShell;

        private IServiceProvider _serviceProvider { get; }

        public NavigationAssistantViewModel(IVsUIShell uiShell, IServiceProvider serviceProvider)
        {
            this.uiShell = uiShell;
            this._serviceProvider = serviceProvider;
        }

        private ICommand changeThemeCommand;

        public ICommand ChangeThemeCommand
        {
            get
            {
                return this.changeThemeCommand ?? (this.changeThemeCommand = new VSCommand(this._serviceProvider, this.uiShell));
            }
        }
   }
}
Byusa
  • 2,279
  • 1
  • 16
  • 21

1 Answers1

0

Without more information, what I've done in the past one of two things.

  1. Refactor each into separate MVVM classes to respect Single Responsibilty Principle.
  2. Create one MVVM class that houses pertinent classes.

    internal class WrapperViewModel
    {
        private IVsUIShell uiShell;
        private IServiceProvider _serviceProvider { get; }
    
        public WrapperViewModel(IVsUIShell uiShell, IServiceProvider serviceProvider)
        {
        }        
    
        //multiple classes
        public NavigationAssistantViewModel NavigationAssistantViewModel { get;set;}
        public MvvmClass2 MvvmClass2 { get;set;}
    }
    
    //multiple classes      
    private class NavigationAssistantViewModel {
    
    }
    
    private class MvvmClass2 {
    
    }
    

Is this helpful? If not could you clarify your question?

w00ngy
  • 1,646
  • 21
  • 25