我如何使用事件VisibilityChanged?

时间:2015-07-14 19:49:25

标签: c# xaml windows-phone-8.1

当应用程序从后台恢复时,我需要重新运行dela方法OnNavigatedTo()中包含的代码。 为此,我需要事件VisibilityChanged: Link MSDN

protected async override void OnNavigatedTo(NavigationEventArgs e)
        {       
            //My code
        }

通过此事件,每次从后台再次打开应用程序时,dell'OnNavigatedTo中包含的代码将再次运行。我该如何使用该活动?我不能。

2 个答案:

答案 0 :(得分:0)

仅当页面不在后台时,才能更改可见性。每次应用打开时,它都会转到OnNavigatedTo(),您可以创建一个bool或计数器来检查它是否是您第一次进入该页面,然后根据OnNavigatedTo内部的内容决定做什么。例如:

private override void OnNavigatedTo(NavigationEventArgs e)
{
     if(hasBeenHere) Repeat_Visit(args);
     else First_Visit(args);
}

答案 1 :(得分:0)

当应用程序从后台恢复时,会激活Application_Activated事件。

来自WP8.1模板的App.xaml.cs:

module Refinery
  module Reviews
    class Review < ...
    end
  end
end

编辑:从app.xaml.cs调用MainPage上的方法已在此处得到解答:How to use a method in MainPage from app.xaml.cs with variable appbar pivot