Closed chobo2 closed 10 years ago
if (navigationService.QueryString.ContainsKey("paramter"))
{
Message = navigationService.QueryString["parameter"];
Spelling mistake?
Opps forgot to change that. I saw that as writing the OP. I fixed that but still not the case as the navigationService still has a count of zero in the query string.
I don't think you'll be able to access the NavigationContext
from the constructor as it is not set at that time... my advice is that you just Dispatcher.BeginInvoke()
on the constructor code, and access the QueryString there!
Ok I will try that, Will that not break the MVVM pattern though? My plan was to use the querystring to pass the id of an item I need for that view and then pull that item out of app storage. Otherwise I am not sure the proper way to send data between views is for the phone(using MVVM Light).
If you are using MVVMLight, then you should use the DispatcherHelper
as that is the proper way of handling this while not breaking the MVVM pattern!
Hey Maybe I am not understanding something but I tried
public SecondVM(INavigationService navigationService)
{
this.navigationService = navigationService;
if (IsInDesignMode)
{
Message = "Design Mode";
}
else
{
DispatcherHelper.CheckBeginInvokeOnUI(() =>
{
if (navigationService.QueryString.ContainsKey("parameter"))
{
Message = navigationService.QueryString["parameter"];
}
});
}
}
and still did not work for me.
You can't use DispatcherHelper.CheckBeginInvokeOnUI()
because given the fact you are running on the UI thread, it will just run the code immediately instead of dispatching it. Use DispatcherHelper.RunAsync()
instead and everything should work ok!
So the View Model is running on the UI already? Changing it to RunAsync worked! Now I have to figure out what is better way to send data between View is.
Those are the 2 ways I found so far.
Hi I am not sure if this is an issue or limitation or what it is. I wanted to to grab a parameter while in the constructor but I don't seem to be able to do this.
but it is always blank. Am I doing something wrong?