Windows phone 8 Windows phone 8如何导航到加载了新用户控件的页面实例?

Windows phone 8 Windows phone 8如何导航到加载了新用户控件的页面实例?,windows-phone-8,user-controls,custom-controls,Windows Phone 8,User Controls,Custom Controls,我不熟悉Windows phone应用程序,正在尝试了解如何实现以下场景: 我有一个包含两个边框的基本页面,我将把不同的视图加载到其中 我希望通过重用该基本页在整个应用程序中维护相同的UI。我知道可以创建BasePage的实例并填充视图。我只是不知道如何导航到这个新实例 BasePage Page1 = new BasePage(); Page1.TopSection.Child = new View1(); Page1.BottomSection.Child = new View2(); /

我不熟悉Windows phone应用程序,正在尝试了解如何实现以下场景:

我有一个包含两个边框的基本页面,我将把不同的视图加载到其中

我希望通过重用该基本页在整个应用程序中维护相同的UI。我知道可以创建BasePage的实例并填充视图。我只是不知道如何导航到这个新实例

BasePage Page1 = new BasePage();
Page1.TopSection.Child = new View1();
Page1.BottomSection.Child = new View2();

//How do I Navigate to  Page1?
--------------------------
|      Top Section       |
|      (load view 1)     |
|                        |
|                        |
--------------------------
|     Bottom Section     |
|      (load view 2)     |
|                        |
--------------------------
|          [ Next Page ] |
-------------------------- 
          BasePage Page2 = new BasePage();
          Page2.TopSection.Child = new View3();
          Page2.BottomSection.Child = new View4();

          //How do I Navigate to  Page2?
          --------------------------
          |      Top Section       |
          |      (load view 3)     |
          |                        |
          |                        |
          --------------------------
          |     Bottom Section     |
          |      (load view 4)     |
          |                        |
          --------------------------
          |          [ Next Page ] |
          --------------------------

您可以导航到
Uri
而不是
页面
实例。您可以尝试用另一种方式来完成此需求。导航到
BasePage
Uri
并传递查询字符串参数以指示应如何自定义
BasePage
。然后在
BasePage
中,根据收到的查询字符串参数进行定制:

//for example, to navigate to Page2 :
NavigationService.Navigate(new Uri("/BasePage.xaml?page=page2", UriKind.Relative));

//on Loaded event :
public BasePage_Loaded()
{
    SetupView();
}

public void SetupView()
{
    string page;
    if(NavigationContext.QueryString.TryGetValue("page", out page))
    {  
        switch (page)
        {
            case "page1" :
                ....... 
                break;
            case "page2" :
                this.TopSection.Child = new View3();
                this.BottomSection.Child = new View4();
                break;
            ....... 
        }
    }
}