【问题标题】:Don't have OnActivated method in app.xaml.cs Windows Phone 8.1在 app.xaml.cs Windows Phone 8.1 中没有 OnActivated 方法
【发布时间】:2014-11-16 23:58:23
【问题描述】:

我实际上正在开发一个最初是空白 Windows Phone 应用程序 8.1 的应用程序。我想用 FileOpenPicker 实现应用程序以从设备获取图片。在 WP 8.1 中,我必须使用 OpenFilePicker 的 PickSingleFileAndContinue 方法。因此,我在此处阅读了有关配置我的项目以处理 Continue 事件的信息: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 只是面对应用程序的状态管理,我无法真正弄清楚该错误来自何处。也许有人有想法?

【问题讨论】:

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


    【解决方案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;
        }
    }
    

    如您所见,它只是一个静态声明。

    【讨论】:

    • 问题是我已经删除了 MainPage.xaml 页面,因为我不需要它。所以我明白有时有一个空白页很有用,所以我创建了 MainPage.xaml。我通过在 App.xaml.cs 上仍然收到相同的错误添加了静态 MainPage 声明:MainPage 突出显示,因为它没有“当前”组件...
    • @HubertSolecki 发布您的 MainPage.xaml.cs(整个文件),除非发生奇怪的事情,否则我看不到这种情况。或者您可以删除该文件并添加 -> 新项目 -> Visual C# -> Windows Phone Portrait Page。将其命名为 MainPage.xaml
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多