在app.xaml.cs Windows Phone 8.1中没有OnActivated方法

时间:2014-11-16 23:58:23

标签: c# xaml windows-phone-8.1 states

我实际上正在处理一个应用程序,该应用程序在开始时是一个空白的Windows Phone应用程序8.1。我想用FileOpenPicker实现应用程序以从设备获取图片。在WP 8.1中,我必须使用OpenFilePicker的 PickSingleFileAndContinue 方法。因此,我已经阅读了有关配置项目以在此处理 继续 事件的信息:your Windows Phone Store app after calling an AndContinue method MSDN。其中一个步骤是在app.xaml.cs文件中实现OnActivated方法。但我的app.xaml.cs中没有OnActivated方法。

我从上面的链接复制粘贴该方法,但该方法中使用的MainPage对象没有当前状态:

 protected async override void OnActivated(IActivatedEventArgs e)
    {
        base.OnActivated(e);

        continuationManager = new ContinuationManager();

        Frame rootFrame = CreateRootFrame();
        await RestoreStatusAsync(e.PreviousExecutionState);

        if (rootFrame.Content == null)
        {
            rootFrame.Navigate(typeof(MainPage));
        }

        var continuationEventArgs = e as IContinuationActivatedEventArgs;
        if (continuationEventArgs != null)
        {
            Frame scenarioFrame = MainPage.Current.FindName("ScenarioFrame") as Frame;
            if (scenarioFrame != null)
            {
                // Call ContinuationManager to handle continuation activation
                continuationManager.Continue(continuationEventArgs, scenarioFrame);
            }
        }

        Window.Current.Activate();
    }

由于我对Windows Phone了解并且只是面对应用程序的状态管理,我无法确定错误的来源。也许有人有个主意?

1 个答案:

答案 0 :(得分:1)

在您从该链接下载完整的源代码示例之前,它不会100%清除。他们忽略了发布完整的例子(代码太多)。下载C#演示项目并查看它。

MSDN FilePicker FULL SOURCE

public sealed partial class MainPage : Page
{
    public static MainPage Current;        

    public MainPage()
    {
        this.InitializeComponent();            

        // This is a static public property that allows downstream pages to get a handle to the MainPage instance
        // in order to call methods that are in this class.
        Current = this;            

        Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    }
}

正如您所看到的,它只是一个静态声明。