我的 Windows8 应用商店应用程序 (xaml) 应用程序中有一个文本文本框,当用户从 Charm 设置中选择共享选项时,我想使其可共享?这可能在 Windows 8 商店 xaml 应用程序中吗?
问问题
222 次
1 回答
0
是的,您需要响应“DataRequested”事件并将文本框的内容添加到数据包中。这是一个代码示例:
JavaScript:
// Call this during initialization
function registerForShare() {
var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
dataTransferManager.addEventListener("datarequested", shareTextHandler);
}
function shareTextHandler(e) {
var request = e.request;
request.data.properties.title = "Your title";
request.data.properties.description = "Description of what you're sharing";
request.data.setText(yourTextBox.Text);
}
C#:
// Call this during initialization
private void ShareSourceLoad()
{
var dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += DataRequested;
}
private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "Your title";
request.Data.Properties.Description = "Description of what you're sharing";
request.Data.SetText(yourTextBox.Text);
}
于 2012-11-29T17:49:52.393 回答