【问题标题】:UWP check the current page for name or instanceUWP 检查当前页面的名称或实例
【发布时间】:2016-09-26 22:48:26
【问题描述】:

在我的 UWP 应用中,我从协议或 toast 启动。在 onactivate 方法中,我想检查应用程序的主视图是否打开或显示的是哪个页面。全部来自 App.xaml.cs

我想做这样的事情:

If Mainpage is not showing --> Navigate(typeof(MainPage));

If main window is not open since i am coming from protocol or toast launch
open frame and navigate to mainpage.

不知道该怎么做。

【问题讨论】:

  • 最好的方法是自己跟踪这一点,以避免页面显示但尚未初始化的边缘状态。但是如果你真的不想跟踪自己的应用状态,你可以问Frame.Content.GetType()
  • 你是一个救生员。您应该将其发布为答案,以便我接受。
  • 继续自己发布答案并接受它。 (这是允许的。)
  • 我知道,但你应该得到它。 ñ=
  • 我允许你。我不需要想象中的互联网点。您可以在答案中提供尽可能多的细节来回答问题。

标签: c# windows windows-runtime win-universal-app uwp


【解决方案1】:

所以我正在检查

var frame = Window.Current.Content as Frame;

if (frame != null)
{
    Type whatpageisit = frame.SourcePageType;
    // handle this page type
}
else
{
    // do what you need to in case window not open
}

【讨论】:

    猜你喜欢
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-12
    • 2015-04-14
    相关资源
    最近更新 更多