WebView.DataTransferPackage 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
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 对象中,并将该对象发送到目标应用进行处理。