无法使“共享”有效

本文关键字:有效 共享 | 更新日期: 2023-09-27 18:34:53

我正在使用密集模板制作 UWP 应用程序,问题是我无法使共享正常工作,因为我不知道如何使用此模板从 app.xaml .cs 导航。

protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
    {
        ShareOperation shareOperation = args.ShareOperation;
        //Can't make any navigation
    }

无法使“共享”有效

你可以获取Microsoft源代码来检索Frame对象

    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();
            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }
        return rootFrame;
    }

并随心所欲地使用

    protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
    {
        var rootFrame = CreateRootFrame();
        // your page and share operation as navigation parameters
        rootFrame.Navigate(typeof(ShareTargetPage), args.ShareOperation);
        Window.Current.Activate();
    }

Microsoft示例项目