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

时间:2013-10-02 09:16:52

标签: c# windows-phone-7 mvvm-light

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

 var msg = new GoToPageMessage() { PageName = "Page2", Params="Index=1" };
 Messenger.Default.Send<GoToPageMessage>( msg );

在MainPage.xaml中,我注册了它:

Messenger.Default.Register<GoToPageMessage>( this, ( action ) => ReceiveMessage( action ) );

和ReceiveMessge如下:

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

我想知道如何在下一页解决这个问题.Params。我不想把它们写到xxx.xaml.cs.有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在其他页面的OnNavigatedTo事件中,您可以通过NavigationContext.QueryString.Keys

查询参数