UWP 协议启动

  • 1.创建通过协议启动的项目 AppDemo
  • 2.在项目的Package.appxmanifest 文件里 Extensions 目录下
复制代码
      <Extensions>
        <uap:Extension Category="windows.protocol">
          <uap:Protocol Name="uridemo">
            <uap:Logo>Assets\StoreLogo.png</uap:Logo>
            <uap:DisplayName>AppDemo</uap:DisplayName>
          </uap:Protocol>
        </uap:Extension>
      </Extensions>
View Code
复制代码
  • 3.在App.xaml.cs里
复制代码
        protected override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);
            // Window management
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                rootFrame = new Frame();
                Window.Current.Content = rootFrame;
            }
            switch (args.Kind)
            {
                case ActivationKind.VoiceCommand:
                    {
                        break;
                    }
                case ActivationKind.Protocol:
                    {
                        // Code specific to launch for results
                        var command = args as ProtocolActivatedEventArgs;

                        if (command.Uri.ToString().StartsWith("uridemo://"))
                        {
                            // Open the page that we created to handle activation for results.
                            rootFrame.Navigate(typeof(MainPage), command);

                        }
                        else
                        {
                            //.....
                        }
                        break;
                    }
            }

            // Ensure the current window is active.
            Window.Current.Activate();
        }
View Code
复制代码
  • 4.在创建一个要启动的项目AppClient
复制代码
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            await Windows.System.Launcher.LaunchUriAsync(new Uri("uridemo://appdata"));
        }
View Code
复制代码
  • 5.部署完成,启动AppClient

作者:androllen

出处:https://www.cnblogs.com/androllen/p/7722827.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   androllen  阅读(484)  评论(0)    收藏  举报
编辑推荐:
· 如何反向绘制出 .NET程序 异步方法调用栈
· 领域驱动设计实战:聚合根设计与领域模型实现
· 突破Excel百万数据导出瓶颈:全链路优化实战指南
· 如何把ASP.NET Core WebApi打造成Mcp Server
· Linux系列:如何用perf跟踪.NET程序的mmap泄露
阅读排行:
· 聊聊 ruoyi-vue ,ruoyi-vue-plus ,ruoyi-vue-pro 谁才是真正的
· C#开发的Panel滚动分页控件 - 开源研究系列文章
· 如何反向绘制出 .NET程序 异步方法调用栈
· ShadowSql之开源不易
· Python 3.14 新特性盘点,更新了些什么?
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
点击右上角即可分享
微信分享提示