WinRT的页面导览树状 [英] WinRt page navigaiton

查看:140
本文介绍了WinRT的页面导览树状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何导航到代码的页面是一个自定义类里面。例如,可以说我有这样的代码在我的MainPage.xaml.cs中:

 私人无效DoSomething的(对象发件人,RoutedEventArgsê )
{
变种工作=新作();
work.doMore();
}

和该类这里就是我想导航到实际发生

 公共类工作
{
公共无效DoMore()
{
//这是我尝试过,但不起作用
变种myFrame =新帧();
myFrame.Navigate(typeof运算(主页));
}
}


解决方案

的你试过不起作用,因为不是主框架代码,你应该发布大型机引用您的代码的其余部分,这样就可以浏览后面的意见之外的代码。
如果你正在简单的东西,我建议把一个静态属性的App类发布主框架实例



编辑:一些代码



 在App.xaml.cs 
公共静态帧大型机{获取;私人集;}

保护覆盖无效OnLaunched(LaunchActivatedEventArgs参数)
{
帧rootFrame = Window.Current.Content的框架;
大型机= rootFrame;
(....)
}
用法:
App.MainFrame.Navigate(...);


How do you navigate to a page from code that is inside of a custom class. For example, lets say I have this code in my MainPage.xaml.cs:

private void DoSomething(object sender, RoutedEventArgs e)
{
   var work = new Work();
   work.doMore();
}

and in this class here is where I would like the navigation to actually take place:

public class Work
{
   public void DoMore()
   {
      // this is what I've tried, but doesn't work
      var myFrame = new Frame();
      myFrame.Navigate(typeof(HomePage));
   }
}

解决方案

The code you tried doesn't work because is not the main frame, you should publish the MainFrame reference to the rest of your code so that you can navigate outside views code behind. If you are making something simple I recommend putting a static property on the App class publishing the main frame instance.

EDIT: Some code

On App.xaml.cs
      public static Frame MainFrame{get;private set;}

      protected override void OnLaunched(LaunchActivatedEventArgs args)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                MainFrame = rootFrame;
(....)
            }
Usage:
       App.MainFrame.Navigate(...);

这篇关于WinRT的页面导览树状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆