简体   繁体   English

如何在Windows Phone应用程序的页面内导航页面

[英]How can i navigate pages inside a page in Windows Phone Application

i am creating a WindowsPhone Application for which i have to navigate to some pages inside my app, but i dont want to leave the MainPage. 我正在创建WindowsPhone应用程序,我必须为其导航至应用程序内的某些页面,但我不想离开MainPage。

Its like a small page inside the MainPage, is there any way possible? 就像MainPage内的一小页一样,有什么办法吗?

I tried creating User Control for the same, but the disadvantage is the User Control loads just after the MainPage is loaded, but i dont want the same. 我尝试为同一用户创建用户控件,但缺点是紧随MainPage加载后才加载用户控件,但我不希望这样。 I want to click somewhere in my app then it loads the next page inside (keeping my application fast) instead of loading all user controls at once on MainPage load event. 我想单击应用程序中的某个位置,然后将其加载到内部的下一页(保持应用程序快速运行),而不是在MainPage加载事件中一次加载所有用户控件。

If there is any alternative way you can help, please respond. 如果您有其他替代方法可以提供帮助,请回复。

There is no way to navigate to a frame while first frame remains open. 当第一帧保持打开状态时,无法导航到某个帧。 and as you cannot use popup due to pivot/panorama. 并且由于枢轴/全景,您无法使用弹出窗口。 you have to stick with the user control approach. 您必须坚持使用用户控制方法。 you can optimize your xaml for performance below are some tips on how to optimize xaml 您可以优化xaml的性能,以下是一些有关如何优化xaml的提示

Optimize loading XAML 优化加载XAML

Edit 编辑

    MyUserControl1 control = new MyUserControl1();
    control.DataContext = //bindable data from usercontrol
    this.ContentRoot.Children.Add(control);

Just have a Frame inside your MainPage. 只需在MainPage内添加一个框架即可。 Navigate to other pages using that frame. 使用该框架导航到其他页面。

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

This is how you navigate from the code behind: 这是您从后面的代码导航的方式:

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 and BasicPage2 are the pages I want to navigate to, inside the MainPage. BasicPage1和BasicPage2是我要导航到MainPage内部的页面。

If your main page has enough free space for your "other page", you can try this: Place another Frame in your main XAML and navigate your other page to that frame. 如果您的主页有足够的可用空间来容纳“其他页面”,则可以尝试以下操作:在主XAML中放置另一个框架,然后将其他页面导航到该框架。 Your main remains visible AND active. 您的主体仍然可见且处于活动状态。

I do that already on bigger screens (Tablets) and know the pitfalls. 我已经在更大的屏幕(平板电脑)上这样做了,并且知道了陷阱。 Do not use the navigation helper for your other page, because you will not navigate back rather then send other "other pages" to that frame. 不要将导航助手用于其他页面,因为您将不会向后导航,而是将其他“其他页面”发送到该框架。 Or remove last backstack entry after navigation. 或在导航后删除上一个后退堆栈条目。

secondFrame.Navigate(pageType, frames);
if (secondFrame.BackStackDepth > 0)
   secondFrame.BackStack.RemoveAt(secondFrame.BackStackDepth - 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Phone 8.1上仅浏览一页 - How to navigate just one page back on Windows Phone 8.1 如何在一页上添加多个屏幕? Windows Phone 7应用程序 - How to add mulitple screen on one page? Windows Phone 7 application 如何在Windows Phone的后台运行我的应用程序或某些特定方法 - How can I run my application or some specific methods in background in windows phone 如何在使用OpenGL的Windows上的同一应用程序内绘制两个单独的3D窗口? - How can I draw inside two separate 3D windows within the same application on Windows using OpenGL? 我如何在Windows Phone的dataTemplate中获取控件? - How i get the control inside dataTemplate in windows phone? 使用Windows Phone应用程序登录页面上的进度栏 - Use progressbar on login page of windows phone application 在Windows 8应用中的页面之间导航 - Navigate between pages in windows 8 apps 如何加快Windows Phone 8.1模拟器的速度? - How can I speed up the Windows Phone 8.1 Emulator? 如何查找Windows Phone 7.5的纬度和经度 - How Can I find latitude and longitude of my Windows Phone 7.5 如何在Windows Phone应用程序中对齐TextBlock的文本? - How to justify the text of a TextBlock in a Windows Phone application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM