C# 如何使用WP7中的MVVMLight页面解析另一个页面中的Uri参数
我在WP7中使用MVVMLight时遇到了一个问题。在ViewModel中创建消息并导航到其他页面时,如下所示:C# 如何使用WP7中的MVVMLight页面解析另一个页面中的Uri参数,c#,windows-phone-7,mvvm-light,C#,Windows Phone 7,Mvvm Light,我在WP7中使用MVVMLight时遇到了一个问题。在ViewModel中创建消息并导航到其他页面时,如下所示: var msg = new GoToPageMessage() { PageName = "Page2", Params="Index=1" }; Messenger.Default.Send<GoToPageMessage>( msg ); private object ReceiveMessage( GoToPageMessage action ) {
var msg = new GoToPageMessage() { PageName = "Page2", Params="Index=1" };
Messenger.Default.Send<GoToPageMessage>( msg );
private object ReceiveMessage( GoToPageMessage action )
{
StringBuilder sb = new StringBuilder( "/Views/" );
sb.Append( action.PageName );
sb.Append( ".xaml" );
NavigationService.Navigate(
new System.Uri( sb.ToString()+"?"+action.Params, System.UriKind.Relative ) );
return null;
}
我想知道如何解决下一页的action.Params。我不想把它们写到xxx.xaml.cs。有什么想法吗?在其他页面的
OnNavigatedTo
事件中,您可以通过NavigationContext.QueryString.Keys
private object ReceiveMessage( GoToPageMessage action )
{
StringBuilder sb = new StringBuilder( "/Views/" );
sb.Append( action.PageName );
sb.Append( ".xaml" );
NavigationService.Navigate(
new System.Uri( sb.ToString()+"?"+action.Params, System.UriKind.Relative ) );
return null;
}