wpf - How do I trap keyboard input from a Popup control -
i wanting receive keyboard input popup control acts root visual touch screen keyboard control. i'm wanting control support keyboard input touch screen input. hook events (previewkeydown , keydown) , never fired.
a popup
not focusable default , if focusable, have have else focusable on popup , focused or give focus in order receive keyboard event.
in other words, if want keyboard event popup
use focusable="true"
, put focusable control textbox
or button
or listbox
, either let user give focus clicking on or manually use focus()
code. if these things previewkeydown
should fire popup
.
here little demonstration program toggle button opens popup
, shows slider increasing whenever previewkeydown
event on popup
:
<grid> <stackpanel> <slider name="slider1"/> <togglebutton x:name="togglebutton1" content="open popup"/> </stackpanel> <popup placementtarget="{binding elementname=togglebutton1}" isopen="{binding ischecked, elementname=togglebutton1, mode=oneway}" focusable="true"> <i:interaction.triggers> <i:eventtrigger eventname="previewkeydown"> <ei:changepropertyaction targetobject="{binding elementname=slider1}" propertyname="value" value="1" increment="true"/> </i:eventtrigger> </i:interaction.triggers> <textbox background="white" focusable="true"> <textbox.text>sample popup content.</textbox.text> </textbox> </popup> </grid>
Comments
Post a Comment