al.x
al.x

Reputation: 33

Launch UWP app from Windows Form - entry point?

I have two projects in my VS2013 solution:

  1. A UWP app that consumes/produces data from/to local json files

    • this gets sideloaded and works a treat
  2. A Windows Form that gets the data from a remote server with Web Services

I want a button on my Form to launch the UWP app once the data is fetched. (I cannot integrate the two as the webservice authentication libraries won't work with W8.1 )

This method launches only my UWP splash screen however. It doesn't get into the code.

 Process.Start("MyUWPApp:");

Do I need something like this:

 Process.Start("MyUWPApp:MyEntryPoint");

Where MyEntryPoint is going to go in the Manifest File on the UWP? I've been trying out all sorts of values for MyentryPoint in the file like: App, MainPage.cs, Main() etc.. I'm not sure if this is the way to go.. anyone?

Upvotes: 3

Views: 2268

Answers (2)

Subrak
Subrak

Reputation: 139

The below code helps for me.Add the code in App.Xaml.cs file.

protected override void OnActivated(IActivatedEventArgs args)
    {
        Initialize(args);
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            // Always navigate for a protocol launch
            rootFrame.Navigate(typeof(MainPage), eventArgs.Uri.AbsoluteUri);
            // Ensure the current window is active
            Window.Current.Activate();
        }
    }

Upvotes: 1

Marian Dolinský
Marian Dolinský

Reputation: 3492

You have to override the OnActivated(IActivatedEventArgs args) method in your App.xaml.cs to handle protocol activation in your UWP app. Take a look here on MSDN where it is explained.

I've implemented it this way and it works perfectly in my app:

private async void Initialize(IActivatedEventArgs args)
{
    // My code copied from original OnLaunched method with some minor changes
}

protected override void OnActivated(IActivatedEventArgs args)
{
    Initialize(args);
}

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Initialize(e);
}

Upvotes: 3

Related Questions