我是窗口电话应用程序的新手,正在尝试了解如何实现以下场景:
我有一个包含两个边框的BasePage,我将把不同的视图加载到其中。
我希望通过重用BasePage在整个应用程序中保持相同的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
而不是Page
实例。您可以尝试用另一种方式来实现此要求。导航到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;
.......
}
}
}