6 comments

  1. on navigating from a viewmodel, I define a static event in the viewmodel then handle it in the view. not exactly an enforceable pattern like a base class or interface, but it does keep things where they belong.

    burton

  2. Burton, yes that is an option too. It still feels wrong because it is neither the ViewModel’s responsibility to navigate (it is to initiate it) nor the View’s. That is why I use a Message broker in WPF and regular Silverlight and have an independent ViewHandler class. The problem seems to be that the Navigate method of the Navigation Service requires the current view.

    Erno de Weerd

  3. Please see this solution: http://www.sharpregion.com/easy-windows-phone-7-navigation/

    It makes it possible to navigate and pass any type of data like this:
    NavigationService.Navigate(data);

    And then to get the data like this:
    var data = NavigationContext.GetData();

    Adrian

  4. Adrian, yes I can see how it works and how it simplifies passing the url around. I solved the GUID and navigation service reference by using the View base class and the App class.

    Erno de Weerd

  5. Erno, please notice that NavigationService is a property of the page. Being a property (well, an instance of some type) – we can create an extension method for it.
    Having the extension method, the solution is generic and accessible from all pages without the need for a base class.

    Adrian

  6. Yes, I did notice that but I trying to have no code in my Views. So I really want the navigation to be executed in my viewmodels.

    Erno de Weerd

Comments are closed.