Reputation: 4443
I have a problem with navigationService
and navigationService.Configure
In my ViewModelLocator
constructor I have:
var navigationService = new NavigationService();
navigationService.Configure("MvvmView",new Uri("/MvvmView1.xaml"));
navigationService.Configure("Main",new Uri("/MainPage.xaml"));
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
MvvmView1.xaml
is in my main folder, the same as MainPage.xaml
.
What is strange - it returns me an error
{System.TypeInitializationException: The type initializer for 'SpaceQuiz.ViewModel.ViewModelLocator' threw an exception. ---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at SpaceQuiz.ViewModel.ViewModelLocator..cctor() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at MS.Internal.TypeProxy.<>c__DisplayClass32.b__2c() at MS.Internal.TypeProxy.CreateInstance(UInt32 customTypeId) at MS.Internal.XamlManagedRuntimeRPInvokes.CreateInstance(XamlTypeToken inXamlType, XamlQualifiedObject& newObject)}
I tried a lot of combinations, like:
navigationService.Configure("MvvmView",new Uri("MvvmView1.xaml"));
navigationService.Configure("MvvmView",new Uri("/MvvmView1"));
navigationService.Configure("MvvmView",new Uri("MvvmView1"));
navigationService.Configure("MvvmView",new Uri("./MvvmView1.xaml"));
navigationService.Configure("MvvmView",new Uri("/MvvmView"));
etc - without any success..
How to register navigation in mvvm light?
Any help would be valuable.
Regards
Upvotes: 0
Views: 656
Reputation: 26
If you're using Mvvm Light v 5.0.2 I Believe you should not use an URI as the second parameter, it should rather be the Typeof(view)
. First you define a string constant for each view class and then configure the navigationservice like this:
//This is in the ViewModelLocator.cs
// Define one key for each view/page.
// You can call them anything but I use my view/class name followed by "Key"
public const string MvvmView1Key = "MvvmView1";
var nav = new NavigationService();
//Updated to reflect SilverLight instead of Store App.
nav.Configure("MvvmView1", new Uri("/MvvmView1.xaml", UriKind.RelativeOrAbsolute));
// Assuming that your view class is called MvvmView1.
Upvotes: 1