How to detect Ctrl+V in Silverlight 4?

老子叫甜甜 提交于 2019-12-07 07:46:17

问题


What is the best way to detect Ctrl+V in Silverlight?

I want to detect Ctrl+V, to get access to the Clipboard.


回答1:


EDIT

To capture the CTRL+V keypress globally in your silverlight application, is fraught with difficulty. Events start at the child elements and bubble down to the parent controls, so simply handling KeyDown on your root UIElement will not work. Any text input control will first get the event and smother it (by setting Handled to true on the event args.) I think that if you use the DOM bridge and subscribe a handler to the browser KeyDown event for the silverlight element itself that you may actually be able to get to it first, and even handle it completely before any silverlight controls can. I think that would be the easiest way to intercept CTRL+V, but I have not tested it.

Original Answer

You should use the System.Windows.Clipboard class.

  • GetText, which retrieves text from the clipboard
  • SetText, which places text on the clipboard
  • ContainsText, which indicates whether the clipboard currently contains text



回答2:


if (e.Key == Key.V)
{
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
    {
        //do what you want on paste
    }
}

You have to use this on the keyUp event. More details can be found here: http://msdn.microsoft.com/en-us/library/cc189015%28VS.95%29.aspx



来源:https://stackoverflow.com/questions/2955466/how-to-detect-ctrlv-in-silverlight-4

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