Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Switching Navigation using Prism,MVVM,Unity

container.RegisterType<object, LabStatusView>("LabStatusView");
Uri LabStatusViewUri = new Uri("pack://application:,,,/LabStatus;component/LabStatusView.xaml",     
UriKind.Absolute);
regionManager.RequestNavigate("HorizonNavigatorView",LabStatusViewUri,NavigationCompleted);

I am using this to navigate to LabStatusView, which seems straightforward.

ObjectStates after the requestNavigate is executed:

  1. regionManager.Regions.ActiveRegion contains one object of type "Object" instead of LabStatusView.
  2. The only quirk of using Unity known to me is that i have register my type using overload of RegiterType method.

Any suggestion what i am doing wrong here ?

like image 405
Jack_2060 Avatar asked Sep 10 '26 06:09

Jack_2060


1 Answers

To Navigate is alot easier to do than in your code. Here's how i did it for a project.

//Register your View on Startup
container.RegisterType<object, LabStatusView>("LabStatusView");

//Navigation works like this
var labStatusView = new Uri("LabStatusView", UriKind.Relative);
regionManager.RequestNavigate("HorizonNavigatorView", labStatusView);

Can you try it like this?

Also many people use static classes for their Region and View name to avoid "magic strings". Something like this.

public class RegionNames
{
  public const string HorizonNavigatorView = "HorizonNavigatorView";
}
public class ViewNames
{
  public const string LabStatusView = "LabStatusView";
}
like image 86
shriek Avatar answered Sep 12 '26 20:09

shriek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!