Don't have OnActivated method in app.xaml.cs Windows Phone 8.1

1.5k views Asked by At

I'm actually working on an application which was a blank Windows Phone app 8.1 at the beginning. I wanted to implement the app with a FileOpenPicker to get a picture from the device. In WP 8.1, I have to use PickSingleFileAndContinue method of the OpenFilePicker. So I've read about configuring my project to handle Continue event here: your Windows Phone Store app after calling an AndContinue method MSDN. One of the steps is to implement the OnActivated method in the app.xaml.cs file.But there is no OnActivated method in my app.xaml.cs.

I've copy paste that method from the above link but the MainPage object used in that method doesn't have a Current state:

 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();
    }

As I'm knew to Windows Phone and just facing the states management of an app, I cannot really figure out where that error comes from. Maybe someone got an idea ?

1

There are 1 answers

2
Chubosaurus Software On

It won't be 100% clear until you download the full source code example off that link. They neglected to post the full example (too much code). Download the C# demo project and look at it.

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;
    }
}

As you can see it's just a static declaration.