共用方式為


WebView.DataTransferPackage 屬性

定義

注意

在Windows 8.1之後,可能會變更或無法使用 DataTransferPackage。 請改用 CaptureSelectedContentToDataPackageAsync

取得傳遞至WebView的剪貼簿DataPackage

public:
 property DataPackage ^ DataTransferPackage { DataPackage ^ get(); };
/// [get: Windows.Foundation.Metadata.Deprecated("Use CaptureSelectedContentToDataPackageAsync instead of DataTransferPackage. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.Foundation.UniversalApiContract)]
DataPackage DataTransferPackage();
/// [get: Windows.Foundation.Metadata.Deprecated("Use CaptureSelectedContentToDataPackageAsync instead of DataTransferPackage. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Foundation.UniversalApiContract")]
DataPackage DataTransferPackage();
public DataPackage DataTransferPackage { [Windows.Foundation.Metadata.Deprecated("Use CaptureSelectedContentToDataPackageAsync instead of DataTransferPackage. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.Foundation.UniversalApiContract))] get; }
public DataPackage DataTransferPackage { [Windows.Foundation.Metadata.Deprecated("Use CaptureSelectedContentToDataPackageAsync instead of DataTransferPackage. For more info, see MSDN.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Foundation.UniversalApiContract")] get; }
var dataPackage = webView.dataTransferPackage;
Public ReadOnly Property DataTransferPackage As DataPackage

屬性值

剪貼簿資料封裝。

屬性

範例

下列程式碼範例示範如何使用這個屬性來實作共用支援。

void SDKSample::WebViewControl::Scenario7::Share_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    dataTransferManager = DataTransferManager::GetForCurrentView();
    dataRequestedToken = dataTransferManager->DataRequested += ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>(this, &Scenario7::dataTransferManager_DataRequested);
    DataTransferManager::ShowShareUI();
}

// Data requested handler
void SDKSample::WebViewControl::Scenario7::dataTransferManager_DataRequested(DataTransferManager^ sender, DataRequestedEventArgs^ args)
{
    DataRequest^ request = args->Request;
    DataPackage^ p = WebView7->DataTransferPackage;
    
    if (p->GetView()->Contains(StandardDataFormats::Text))
    {
        p->Properties->Title = "WebView Sharing Excerpt";
        p->Properties->Description = "This is a snippet from the content hosted in the WebView control";
        request->Data = p;
    }
    else
    {
        request->FailWithDisplayText("Nothing to share");
    }
    dataTransferManager->DataRequested -= dataRequestedToken;
}
private void Share_Click(object sender, RoutedEventArgs e)
{
    dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += dataTransferManager_DataRequested;
    DataTransferManager.ShowShareUI();
}

void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    DataRequest request = args.Request;
    DataPackage p = WebView7.DataTransferPackage;

    if (p.GetView().Contains(StandardDataFormats.Text))
    {
        p.Properties.Title = "WebView Sharing Excerpt";
        p.Properties.Description = "This is a snippet from the content hosted in the WebView control";
        request.Data = p;
    }
    else
    {
        request.FailWithDisplayText("Nothing to share");
    }
    dataTransferManager.DataRequested -= dataTransferManager_DataRequested;
}
Private Sub Share_Click(sender As Object, e As RoutedEventArgs)
    dataTransferManager = dataTransferManager.GetForCurrentView()
    AddHandler dataTransferManager.DataRequested, AddressOf dataTransferManager_DataRequested
    dataTransferManager.ShowShareUI()
End Sub

Private Sub dataTransferManager_DataRequested(sender As DataTransferManager, args As DataRequestedEventArgs)
    Dim request As DataRequest = args.Request
    Dim p As DataPackage = WebView7.DataTransferPackage

    If p.GetView().Contains(StandardDataFormats.Text) Then
        p.Properties.Title = "WebView Sharing Excerpt"
        p.Properties.Description = "This is a snippet from the content hosted in the WebView control"
        request.Data = p
    Else
        request.FailWithDisplayText("Nothing to share")
    End If
    RemoveHandler dataTransferManager.DataRequested, AddressOf dataTransferManager_DataRequested
End Sub

備註

此屬性通常用來支援共用。 在共用作業期間,來源應用程式會將共用的資料放在 DataPackage 物件中,並將該物件傳送至目標應用程式進行處理。

適用於

另請參閱