Gena Verdel
Gena Verdel

Reputation: 636

Navigation using Caliburn.Micro

I was wondering what is the most conventional way to navigate between two unrelated view models using Caliburn.Micro? Let's say there's a tree of view models in one part of the application: ParentViewModel->ChildVM1->ChildVM2 and etc. Additionally there's an OmniVM which should be able to navigate to any of the aforementioned view models. By "navigating" I mean locating the appropriate instance (the activation part is straightforward after that). I don't want to involve any usage of IEventAggregator, nor Container.Resolve kind of stuff. Thanks for the response

Upvotes: 0

Views: 1650

Answers (1)

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

devdigital said it in the comment and i am going to say it here again and as Rob (the architect who wrote the framework) would say it, Architecture matters in the UI too. This means you should consider how your presentation layer is organized. In other words, are you going to have a tabbed interface where the main window would be a Caliburn.Micro Conductor and the tabs conducted Screens, or are you going to have a Visual Studio kind of UI that uses docking windows and tool bars, consider this type of thinking when building the UI. Now if you don't like architecture and you just want to design your GUI then i could tell you that Screen and Conductor are the most important classes to consider for navigation. I Strongly Advise you to read the Screens, Conductors and Compositions article if you haven't already done so, it will give you an idea of what i am talking about and a bunch of helpful thoughts.

Edit: For your specific situation and since you have this deeply nested structure i would create an interface for navigation on the MenuViewModel, something like this:

public interface IMenuNavigator {
    void NavigateToItem(Item i);
}

Then i would inject this into those inner view models, i think you have a feeling of what i mean. On the other hand, you can also use the IEventAggregator which is used for loosely coupled communication between unrelated components (viewmodels) such as in your situation, so you publish messages on the aggregator for navigation and the MenuViewModel listens to those and handles them correctly. You may even come with a better idea depending on your specific internal situation. Hope that helps.

Upvotes: 1

Related Questions