Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用WP7中的MVVMLight页面解析另一个页面中的Uri参数_C#_Windows Phone 7_Mvvm Light - Fatal编程技术网

C# 如何使用WP7中的MVVMLight页面解析另一个页面中的Uri参数

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 ) {

我在WP7中使用MVVMLight时遇到了一个问题。在ViewModel中创建消息并导航到其他页面时,如下所示:

 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;
  }