1
votes

I am developing a ribbon WPF application using MVVM. The ribbon uses API Fluent Ribbon Control Suite; the MVVM framework uses Caliburn Micro, and DI uses Ninject.

What I observed is that when the application grows, the MainViewModel for view MainView keeps growing too. The 1st question: is it ever possible to separate the MainViewModel into multiple VMs? Or rather, multiple VMs control the same MainView that contains ribbons?

And the 2nd question is under this scenario:

The area under ribbon displays different Views when the user press buttons in the ribbon, that is, the "ActiveItem" is changed into other Views like GlobalDataView or BreakdownDataView etc.:

    <Grid x:Name="SubView" Background="White">
        <ContentControl x:Name="ActiveItem" />
    </Grid>

Say now GlobalDataView is activated (assigned into the ContentControl), a contextual ribbon tab is shown upon the view's activation, and we assume that the contextual ribbon is with VM "ContextualRibbonGlobalDataViewModel" if there is a good solution for Question1. Also, the GlobalDataView itself also has its own VM called "GlobalDataViewModel". My question is: will it be possible to combine ContextualRibbonGlobalDataViewModel and GlobalDataViewModel? Since they both contain logic very specific to the GlobalDataView.

If Q1 is not possible, is there a way to let GlobalDataViewModel controls the contextual ribbon inside MainView?

My current approach is MainViewModel (MainView) + GlobalDataViewModel (GlobalDataView), such that the MainViewModel contains all the commands (actions in CM) for the GlobalData's view's contextual ribbon. MainViewModel has to use a mediator (the EventAggregator in CM) to talk to GlobalDataViewModel.

Thanks.

1

1 Answers

0
votes

In my application, I have a "ShellView" Mainmodel, which contains multiple sub-containers. So it is entirely possible, especially if the sub-items are logically related and separated from the other parts. Learning how to do it was a little cumbersome, but It boils down to:

    [ImportingConstructor]
    public ShellViewModel(IWindowManager windowManager, IEventAggregator events)
    {
        this.windowManager = windowManager;
        this.logger = NLog.LogManager.GetCurrentClassLogger();
        this.events = events;
        events.Subscribe(this);
    }

Load another view:

  public async void loadview()
  {
    this.ActivateItem(new BlaViewModel(this.events, this.windowManager));
    //displaying it in a tabcontrol, which is defined in XAML. It would probably work with something else too
    var thisView = (ShellView)this.GetView();
    thisView.BlaViewM.SelectedItem
}

In the new view:

public PowerPointViewModel(, IEventAggregator events, IWindowManager windowManager)
{
    this.logger = NLog.LogManager.GetCurrentClassLogger();

    events.Subscribe(this);
    this.events = events;
    this.DisplayName = "BLA";

    this.windowManager = windowManager;
}

I am using events to pass messages around, especially if there needs to be interaction between the separate viewmodels. There is an ok tutorial to find from the author: http://devlicio.us/blogs/rob_eisenberg/archive/2010/10/08/caliburn-micro-soup-to-nuts-part-6a-screens-conductors-and-composition.aspx

Can you elaborate a bit on your second question? I am not sure if I understand you correctly. But I think you are having too muc logic in your ribbon. My ribbons are simply launching events, which are send to the specific viewmodel, which may talk to the Data access layer. So, my ribbons are specific to a certain Viewmodel, too. But there is no need for them to do much. Som thinks like dropdowns are relying on the Viewmodel-methods to get a the values to display, but they do nothing more.