Steps to Navigate from One View to Another in MVVM

Introduction

This article contains details introduction about to dynamically navigate user from one view to another view in MVVM. it is very simple to navigate user to one view to another using code behind.

follow the bellow steps

Steps to navigate without Query string

  1. Clear the Current Region
  2. Locally save the reference of current region.

    IRegion region = regionManager.Regions[RegionNames.ContentRegion];
     
  3. Create the object of Uri class and in the constructor pass the View name and kind of uri

    var viewUri = new Uri(ViewName, UriKind.Relative);
     
  4. Call the RequestNavigate function

    region.RequestNavigate(viewUri);

Steps to navigate with Query string

Navigate view with query string is also simple in MVVM, but defferent is that in the uri constructor u have to mention the query string.

See the bellow steps

Steps

  1. Clear the Current Region
  2. Locally save the reference of current region.

    IRegion region = regionManager.Regions[RegionNames.ContentRegion];
     
  3. Declare the variable want to pass with query. Example

    string qry="ImageID=1";
     
  4. Create the object of Uri class and in the constructor pass the View name with query string and kind of uri

    var viewUri = new Uri(ViewName+qry, UriKind.Relative);
     
  5. Call the RequestNavigate function

    region.RequestNavigate(viewUri);
Ebook Download
View all
Learn
View all