Reputation:
I'm making a software in WPF . Within the solution I added other projects , one of which is universal app windows . My question is , I would need to start the project WPF project universal app , wandering through the network did not find much . And ' possible?
In summary , by clicking a button in the project WPF , it must begin with the universal app .
It's possible ? Thank you
Upvotes: 0
Views: 500
Reputation: 10744
The way to launch Windows apps is to use Launcher.LaunchUriAsync.
// The URI to launch
string uriToLaunch = @"cameracapture:CaptureImage?folder=C%3A%5C%5CMyImages";
// Create a Uri object from a URI string
var uri = new Uri(uriToLaunch);
// Launch the URI
async void DefaultLaunch()
{
// Launch the URI
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
For this to work you will need a URI scheme for your app. To handle a URI association, specify the corresponding URI scheme name in the app manifest file. Go to your app’s package.appxmanifest file and navigate to the Declarations tab. You want to add a new declaration of type ‘Protocol’ and you’ll need to specify the name property which will be the actual URI protocol you want your app to handle. e.g. cameracapture.
To handle the incoming parameters override the OnActivated method in the App.xaml.cs code behind:
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
var eventArgs = args as ProtocolActivatedEventArgs;
if (eventArgs != null)
{
var uri = eventArgs.Uri;
tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
// URI association launch for cameracapture.
if (tempUri.Contains("cameracapture:CaptureImage?folder="))
{
// Get the folder (after "folder=").
int folderIndex = tempUri.IndexOf("folder=") + 7;
string folder = tempUri.Substring(folderIndex);
// Do something with the request
}
}
}
}
Upvotes: 1