Windows Phone 8.1 股份合约

Windows Phone 8.1 Share Contract

我写了一个WindowsPhone8.1 (WINRT) App。我正在尝试从我的应用程序共享 image,它位于应用程序的 LocalStorage 中。我正在使用 Windows Phone 8.1 份额合约。

private async void OnShareDataRequested(DataTransferManager sender, DataRequestedEventArgs _dataRequestedEventArgs)
{
    _dataRequestedEventArgs.Request.GetDeferral();
    List<StorageFile> ListObject = new List<StorageFile>();
    Uri UriObject = new Uri(FileLocation,UriKind.RelativeOrAbsolute);

    _dataRequestedEventArgs.Request.Data.Properties.Title = "Dr. App";
    _dataRequestedEventArgs.Request.Data.Properties.Description = "Photo from my Dr. App Album.";


    StorageFolder StorageFolderObject;
    StorageFile StorageFileObject;
        try
        {

            StorageFolderObject = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFolderAsync(LocalCache);
            StorageFileObject = await StorageFolderObject.GetFileAsync(FileNameSaved);

            _dataRequestedEventArgs.Request.Data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromFile(StorageFileObject);
            _dataRequestedEventArgs.Request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(StorageFileObject));


            ListObject.Add(StorageFileObject);
            _dataRequestedEventArgs.Request.Data.SetStorageItems(ListObject);
        }
        catch(Exception ex_)
        {

        }
        finally
        {
            _dataRequestedEventArgs.Request.GetDeferral().Complete();

        }


}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    DataTransferManager.GetForCurrentView().DataRequested -= OnShareDataRequested;
    base.OnNavigatedFrom(e);
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    DataTransferManager.GetForCurrentView().DataRequested += OnShareDataRequested;
    base.OnNavigatedTo(e);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
    DataTransferManager.ShowShareUI();
}

I am getting PREPARING CONTENT TO SHARE and then it vanishes in a second. ShareUI doesnt open.

文档指出异步工作的上限为 200 毫秒。你违反这个前提了吗?

DataRequest.GetDeferral(): Use this method when you want to use an asynchronous function call to generate the DataPackage during a share operation. This function must return a DataPackage object within 200ms to prevent the operation from timing out. If your app shares content that takes more time to package, such as a collection of files or photos, don't use this method. Instead, use the SetDataProvider method to assign a delegate to a DataPackage and return that DataPackage to the target app.

当我查看您的代码时,另一件让我印象深刻的事情是您调用了两次 GetDeferral 方法,而不是保存第一次调用的结果。