C# 启动到其他应用程序
我有一个按钮,单击该按钮将打开其他应用程序(如果您已经有该应用程序)或指向windows应用商店(如果它没有该应用程序)。但是我有一个问题,那就是:当我有了应用程序并且点击按钮时,只显示初始屏幕,无法打开应用程序 XAML: 如何处理 当我拥有应用程序并单击按钮时,仅显示启动屏幕,无法打开应用程序 使用Windows.System.Launcher.LaunchUriAsync打开应用程序时不会触发C# 启动到其他应用程序,c#,uwp,protocols,C#,Uwp,Protocols,我有一个按钮,单击该按钮将打开其他应用程序(如果您已经有该应用程序)或指向windows应用商店(如果它没有该应用程序)。但是我有一个问题,那就是:当我有了应用程序并且点击按钮时,只显示初始屏幕,无法打开应用程序 XAML: 如何处理 当我拥有应用程序并单击按钮时,仅显示启动屏幕,无法打开应用程序 使用Windows.System.Launcher.LaunchUriAsync打开应用程序时不会触发App.xaml.cs中目标应用程序的OnLaunchedMethod。因此,不会为目标应用程序创
App.xaml.cs
中目标应用程序的OnLaunchedMethod
。因此,不会为目标应用程序创建根框架。因此,您只能看到启动屏幕
要解决此问题,您需要手动创建目标应用程序的根框架。您可以在中实现这一点:打开您的目标应用程序和App.xaml.cs内部,并添加以下代码:
private Frame CreateRootFrame()
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
rootFrame.NavigationFailed += OnNavigationFailed;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
return rootFrame;
}
更新:创建框架的过程应在on激活状态下进行
方法:
protected override void OnActivated(IActivatedEventArgs args)
{
var rootFrame = CreateRootFrame();
rootFrame.Navigate(typeof(MainPage));//here navigate to typeof(YourPageName)
Window.Current.Activate();
}
当我拥有应用程序并单击按钮时,仅显示启动屏幕,无法打开应用程序
使用Windows.System.Launcher.LaunchUriAsync打开应用程序时不会触发App.xaml.cs
中目标应用程序的OnLaunchedMethod
。因此,不会为目标应用程序创建根框架。因此,您只能看到启动屏幕
要解决此问题,您需要手动创建目标应用程序的根框架。您可以在中实现这一点:打开您的目标应用程序和App.xaml.cs内部,并添加以下代码:
private Frame CreateRootFrame()
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
rootFrame.NavigationFailed += OnNavigationFailed;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
return rootFrame;
}
更新:创建框架的过程应在on激活状态下进行
方法:
protected override void OnActivated(IActivatedEventArgs args)
{
var rootFrame = CreateRootFrame();
rootFrame.Navigate(typeof(MainPage));//here navigate to typeof(YourPageName)
Window.Current.Activate();
}
此示例将对您有所帮助,请单击 在启动的应用程序中,您需要配置
package.appxmanifest
。下面是XML的核心配置
<Package>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="CSReceiveUri.App">
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="test-launchmainpage">
<uap:DisplayName>test-launchmainpage</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="test-launchpage1">
<uap:DisplayName>test-launchpage1</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
</Extensions>
</Application>
</Applications>
</Package>
此示例将对您有所帮助,请单击 在启动的应用程序中,您需要配置
package.appxmanifest
。下面是XML的核心配置
<Package>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="CSReceiveUri.App">
<Extensions>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="test-launchmainpage">
<uap:DisplayName>test-launchmainpage</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="test-launchpage1">
<uap:DisplayName>test-launchpage1</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
</Extensions>
</Application>
</Applications>
</Package>
我已尝试在App.xaml.cs上添加上述代码,但它仍然只显示一个初始屏幕是的,我将代码添加到目标应用程序并运行该应用程序。您可以共享目标应用程序的基本示例吗?以下是目标应用程序的基本示例:抱歉,犯了一个错误,应在App.xaml.cs中应用,而不是
OnShareTargetActivated
。我已经更新了我的答案,请检查:)我尝试在App.xaml.cs上添加上面的代码,但它仍然只显示一个启动屏幕是的,我将代码添加到目标应用并运行该应用。你可以共享目标应用的基本示例吗?这是目标应用的基本示例:抱歉,犯了一个错误,应该应用到App.xaml.cs中,未激活共享设置上的
。我已经更新了答案,请检查:)