visual studio - Default enter and space key behavior wpf applications -
i'm trying put small application in wpf (a media player) using visual studio 2012 express desktop, , want use space bar pause. unfortunately, space bar, enter key, seem have default behavior in (just before execute commands have programmed them) re-execute or re-raise recent event in window (button clicks, keypresses, etc.).
i have tried overriding onkeydown, onkeyup, onpreviewkeydown, , onpreviewkeyup in every combination, no amount of overriding eliminates behavior. have found true in other wpf applications wrote, , in windows forms application put few months ago. default aspect of applications built visual studio? , more importantly, there way rid of it?
if override onpreviewkeydown
can add logic want, set e.handled
true
, prevent event bubbling , causing behavior seeing.
private void window_previewkeydown(object sender, keyeventargs e) { if (e.key == key.enter || e.key == key.space) { //your logic e.handled = true; } }
Comments
Post a Comment