【问题标题】:Why doesn't my Windows Store (Metro) app appear in the Share Pane?为什么我的 Windows 应用商店 (Metro) 应用程序没有出现在共享窗格中?
【发布时间】:2013-08-02 11:41:02
【问题描述】:

我已将我的应用设置为共享目标(和源),并且我可以成功地与其他应用共享我的应用的内容,但是当我在另一个应用(例如 Mail 或 IE)中时,我无法与我的应用程序,因为它没有作为可用的共享目标应用程序出现在共享窗格中。

我已阅读并遵循 MSDN 文档,检查了示例,并且还在 Package.AppXManifest 文件中设置了共享目标声明。

为什么,我该如何解决这个问题?


C# 代码隐藏:

    ShareOperation shareOperation;
    private string sharedDataTitle;
    private string sharedDataDescription;
    private string shareQuickLinkId;
    private string sharedText;
    private Uri sharedUri;
    private IReadOnlyList<IStorageItem> sharedStorageItems;
    private string sharedCustomData;
    private string sharedHtmlFormat;
    private IReadOnlyDictionary<string, RandomAccessStreamReference> sharedResourceMap;
    private IRandomAccessStreamReference sharedBitmapStreamRef;
    private IRandomAccessStreamReference sharedThumbnailStreamRef;

    private void ReportStarted()
    {
        this.shareOperation.ReportStarted();
    }

    private void ReportCompleted()
    {
        this.shareOperation.ReportCompleted();
    }

    protected override async void OnNavigatedTo(NavigationEventArgs e)
    {
        RegisterForShare();

        try
        {
            this.shareOperation = (ShareOperation)e.Parameter;
            await Task.Factory.StartNew(async () =>
                {
                    ReportStarted();
                    // Retrieve data package properties.
                    this.sharedDataTitle = this.shareOperation.Data.Properties.Title;
                    this.sharedDataDescription = this.shareOperation.Data.Properties.Description;
                    this.shareQuickLinkId = this.shareOperation.QuickLinkId;

                    // Retrieve data package content.
                    if (this.shareOperation.Data.Contains(StandardDataFormats.Text))
                    {
                        try
                        {
                            this.sharedText = await this.shareOperation.Data.GetTextAsync();
                        }
                        catch (Exception exception)
                        {
                            // NotifyUser of error.
                        }
                    }
                    else if(this.shareOperation.Data.Contains(StandardDataFormats.Html))
                    {
                        try
                        {
                            this.sharedHtmlFormat = await this.shareOperation.Data.GetHtmlFormatAsync();
                        }
                        catch (Exception exception)
                        {

                        }
                    }
                    else if (this.shareOperation.Data.Contains(StandardDataFormats.Uri))
                    {
                        try
                        {
                            this.sharedUri = await this.shareOperation.Data.GetUriAsync();
                        }
                        catch (Exception exception)
                        {

                        }
                    }

                    // Get back to the UI thread.
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                        {
                            if (this.sharedText != null)
                            {
                                // Create a Note out of shared data.
                                CreateNote(this.sharedDataTitle, this.sharedText, null);
                                this.shareOperation.ReportDataRetrieved();
                            }

                            if (this.sharedUri != null)
                            {
                                CreateNote(this.sharedDataTitle, this.sharedUri.OriginalString, null);
                                this.shareOperation.ReportDataRetrieved();
                            }

                            if (this.sharedHtmlFormat != null)
                            {
                                CreateNote(this.sharedDataTitle, this.sharedHtmlFormat.ToString(), null);
                                this.shareOperation.ReportDataRetrieved();
                            }
                        });
                });
        }
        catch (Exception exception)
        {
            Debug.WriteLine(exception.Message);

        }

        if (e.NavigationMode == NavigationMode.Back)
        {
            navigatedBack = true;


        }

        base.OnNavigatedTo(e);
    }

App.xaml.cs:

    protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
    {
        var rootFrame = new Frame();
        rootFrame.Navigate(typeof(MainPage), args.ShareOperation);
        Window.Current.Content = rootFrame;
        Window.Current.Activate();
    }

任何帮助将不胜感激。

【问题讨论】:

    标签: c# .net xaml microsoft-metro windows-store-apps


    【解决方案1】:

    在你的包清单中,确保你添加了“共享目标”的声明

    【讨论】:

    • 正如我的问题所述,我已经这样做了。它仍然不起作用。我什至提供了所有相关的数据格式和支持的文件类型。
    • 问题出在声明中,这就是 windows 知道它可以共享给应用程序的方式。也许您添加了它,但没有正确设置它。
    • 谢谢@Javalsu。在其中一种数据格式之前有一段时间。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2014-03-10
    • 2012-12-07
    相关资源
    最近更新 更多