locked
[UWP] [MVVM] Navigation RRS feed

  • Question

  • Hi,

    I'm just learning MVVM pattern at some tutorials online. And, I'm just getting started using MVVM Light. I learn that MVVM used to make our code behind class contains minimal code or no code at all (no code behind). I was using code behind all the time before, on my beginning of my UWP learning. Navigation using code behind is simple.

    Now, I would like to know how to handle navigation using MVVM pattern. From what I can imagine from MVVM pattern, I can use these option:

    1. Using Message method to trigger code behind navigation.

    2. Direct Command method to change Frame value. 

    3. I'm still searching for other method . . .

    Any suggestion how to do navigation properly in MVVM pattern ?

    Thank You

    Best Regards


    Adityo Setyonugroho


    Thursday, March 3, 2016 7:55 AM

Answers

  • I don't think there is a 'properly' answer here. I would take it back a step and look at what benefits you get from MVVM. If you're trying to increase the Single Responsibility and provide testing then maybe a message pattern is more suited. i.e. If you need to navigate from your main page to an about page, what you're actually saying is that the user wants to see about information. How you choose to implement that might vary over time. E.g. perhaps it's a navigation today, perhaps it's a popup, or even just a message box. Having said all that, 99% of the time code doesn't change that drastically, especially if the project is small. So "depends" on how much infrastructure noise you want to create vs. how likely you think you benefit from using them.

    http://pauliom.wordpress.com

    Thursday, March 3, 2016 8:37 AM
  • Hello Adityo Setyonugroho,

    I usually use NavigationService Class.

    Please see: WinRT: MVVM Navigation and a MVVM Example App & you can see the offcial sample for UWP at Navigation menu (XAML) and get some hints. 

    With Regards,

    Krunal Parekh 


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, March 4, 2016 6:26 AM

All replies

  • I don't think there is a 'properly' answer here. I would take it back a step and look at what benefits you get from MVVM. If you're trying to increase the Single Responsibility and provide testing then maybe a message pattern is more suited. i.e. If you need to navigate from your main page to an about page, what you're actually saying is that the user wants to see about information. How you choose to implement that might vary over time. E.g. perhaps it's a navigation today, perhaps it's a popup, or even just a message box. Having said all that, 99% of the time code doesn't change that drastically, especially if the project is small. So "depends" on how much infrastructure noise you want to create vs. how likely you think you benefit from using them.

    http://pauliom.wordpress.com

    Thursday, March 3, 2016 8:37 AM
  • Hi,

    Thanks for your reply. It is gonna take some times to think over about what pattern or design that should I do on my development. I need to learn more on MVVM rules I think haha. For a moment, any suggestion on doing MVVM Navigation ? what usually do you use ?

    Thank You

    Best Regards


    Adityo Setyonugroho

    Thursday, March 3, 2016 11:30 AM
  • Hello Adityo Setyonugroho,

    I usually use NavigationService Class.

    Please see: WinRT: MVVM Navigation and a MVVM Example App & you can see the offcial sample for UWP at Navigation menu (XAML) and get some hints. 

    With Regards,

    Krunal Parekh 


    Thanks MSDN Community Support Please remember to Mark as Answer the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, March 4, 2016 6:26 AM
  • Hi,

    Sorry for my late reply, thanks for giving me some idea on doing Navigation on UWP. I'll again on those sample.

    Thank You

    Best Regards


    Adityo Setyonugroho

    Saturday, March 5, 2016 3:20 AM