是否有与文本框控件的 HTML onCopy 事件等效的 WPF?我想在将文本复制到剪贴板之前进行一些处理。
您可以使用
CommandManager.PreviewExecuted
路由事件。当调用 RoutedCommand 上的 Execute 方法时会引发此问题。
在构造函数中:
CommandManager.AddPreviewExecutedHandler(textBox, onPreviewExecuted);
功能:
private void onPreviewExecuted(object sender, ExecutedRoutedEventArgs e)
{
// Check if the executed command is a copy command
if (e.Command == ApplicationCommands.Copy)
{
// Custom processing here
// ...
// Mark the event as handled to prevent the default copy operation
e.Handled = true;
}
}