'OperationCompleted' event not raised after 'Paste' operation

一个人想着一个人 提交于 2019-12-13 03:28:17

问题


The OperationCompleted event is supposed to be raised at the end of a Clipboard Paste operation as mentioned in DataPackage:

OperationCompleted Occurs when a paste operation is completed.

It's not.

Why? / What's a workaround?

Code:

static void CopyToClipboard(string s)
{
    DataPackage dataPackage = new DataPackage();
    dataPackage.SetText(s);
    dataPackage.OperationCompleted += DataPackage_OperationCompleted1;
    Clipboard.SetContent(dataPackage);
}
static void DataPackage_OperationCompleted1(DataPackage sender, OperationCompletedEventArgs args)
{
    throw new NotImplementedException();
}

回答1:


Please see the Remarks section on the document.

This event occurs when a user or program pastes content from the Clipboard. If your app is using the DataPackage for share operations, you do not have to handle this event.

Then, in your paste handler method, you would need to use dataPackageView.ReportOperationCompleted() method to inform the system that your app is finished using the DataPackageView object.

I used the official Clipboard code sample to test.

In this line, I added the following code:

dataPackageView.ReportOperationCompleted(DataPackageOperation.Copy);

After that, the DataPackage's OperationCompleted event would be fired.



来源:https://stackoverflow.com/questions/50100233/operationcompleted-event-not-raised-after-paste-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!