[英]Query String Not Getting Set - Cimbalino Windows Phone
I am using Cimbalino navigation but the query param never gets set for me. 我正在使用Cimbalino导航,但从未为我设置查询参数。
Main View Model 主视图模型
private readonly INavigationService navigationService = null;
public MainViewModel(INavigationService navigationService)
{
this.navigationService = navigationService;
NavigateToPg2Cmd = new RelayCommand(() => NaviagateToPg2());
NavigateToPg2WithParmsCmd = new RelayCommand(() => NaviagateToPg2WithParms());
}
private void NaviagateToPg2WithParms()
{
navigationService.NavigateTo(new Uri("/Views/SecondPg.xaml?parameter=1&parm2=2", UriKind.Relative));
}
When I look into NavigationService the Query Param dictionary is always 0. 当我查看NavigationService时,Query Param字典始终为0。
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
}
else
{
}
SimpleIoc.Default.Register<INavigationService, NavigationService>();
SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<SecondVM>();
}
Edit Ok, I figured it out. 编辑,确定了。 When NavigateTo runs it still has not split the query string out yet so that's why it is zero.
当NavigateTo运行时,它仍然没有拆分查询字符串,因此这就是零。
I was also trying to do 我也在尝试做
private readonly INavigationService navigationService = null;
public SecondVM(INavigationService navigationService)
{
this.navigationService = navigationService;
if (IsInDesignMode)
{
Message = "Design Mode";
}
else
{
if (navigationService.QueryString.ContainsKey("paramter"))
{
Message = navigationService.QueryString["parameter"];
}
}
}
what did not work either as I guess it was too early as well. 还是没有用,因为我想还为时过早。 I really would like to pull it out at constructor time though, is there a way to do this?
我真的很想在构造函数时将其拔出,有没有办法做到这一点?
I know it's not 100% the solution you are looking for, but you are true... You'll need to wait until the view is loaded before accessing the QueryString params in the ViewModel! 我知道这不是您要寻找的解决方案的100%,但是您是真的……您需要等到加载视图后才能访问ViewModel中的QueryString参数!
To do this, hook into the Loaded
event of the view and pass it to a Command
on the viewmodel! 为此,请钩住视图的
Loaded
事件并将其传递给视图模型上的Command
!
If created a demo of this on my github to get you started: https://github.com/Depechie/NavigationParams 如果在我的github上创建了此演示以开始使用: https : //github.com/Depechie/NavigationParams
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.