[英]How can i navigate pages inside a page in Windows Phone Application
我正在創建WindowsPhone應用程序,我必須為其導航至應用程序內的某些頁面,但我不想離開MainPage。
就像MainPage內的一小頁一樣,有什么辦法嗎?
我嘗試為同一用戶創建用戶控件,但缺點是緊隨MainPage加載后才加載用戶控件,但我不希望這樣。 我想單擊應用程序中的某個位置,然后將其加載到內部的下一頁(保持應用程序快速運行),而不是在MainPage加載事件中一次加載所有用戶控件。
如果您有其他替代方法可以提供幫助,請回復。
當第一幀保持打開狀態時,無法導航到某個幀。 並且由於樞軸/全景,您無法使用彈出窗口。 您必須堅持使用用戶控制方法。 您可以優化xaml的性能,以下是一些有關如何優化xaml的提示
編輯
MyUserControl1 control = new MyUserControl1();
control.DataContext = //bindable data from usercontrol
this.ContentRoot.Children.Add(control);
只需在MainPage內添加一個框架即可。 使用該框架導航到其他頁面。
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="TitlePanel" Grid.Row="0">
<StackPanel Orientation="Vertical">
<TextBlock Text="Title" />
<Button Click="Button_Click"
Content="Page1"
Tag="SharedFrame.BasicPage1" />
<Button Click="Button_Click"
Content="Page2"
Tag="SharedFrame.BasicPage2" />
</StackPanel>
</Grid>
<Grid x:Name="ContentPanel" Grid.Row="1">
<Frame x:Name="rootFrame" />
</Grid>
</Grid>
這是您從后面的代碼導航的方式:
private void Button_Click(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
if (b != null && b.Tag != null)
{
Type pageType = Type.GetType(b.Tag.ToString());
if (pageType != null && rootFrame.CurrentSourcePageType != pageType)
{
rootFrame.Navigate(pageType);
}
}
}
BasicPage1和BasicPage2是我要導航到MainPage內部的頁面。
如果您的主頁有足夠的可用空間來容納“其他頁面”,則可以嘗試以下操作:在主XAML中放置另一個框架,然后將其他頁面導航到該框架。 您的主體仍然可見且處於活動狀態。
我已經在更大的屏幕(平板電腦)上這樣做了,並且知道了陷阱。 不要將導航助手用於其他頁面,因為您將不會向后導航,而是將其他“其他頁面”發送到該框架。 或在導航后刪除上一個后退堆棧條目。
secondFrame.Navigate(pageType, frames);
if (secondFrame.BackStackDepth > 0)
secondFrame.BackStack.RemoveAt(secondFrame.BackStackDepth - 1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.