Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Using Keys to call Commands (Read 2438 times)
DavidM
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Aug 13th, 2018
Using Keys to call Commands
Sep 24th, 2018 at 1:20pm
Print Post  
How would you override the default behaviour of a key to trigger a command?
In context: I have a NumPad template which i would like to add a couple of "ExtendedKeys" Exit and Enter. We would like to add a binding to these 2 keys to trigger a Command on a ViewModel.
if i understand correctly, i can do this by listening to the Keyboard MouseEvents and check for keycode, then i should be able to Execute my Command from the View/Control codebehind...
That is fine but how if possible will you do it from a (lest say, a Style).
Must add we are trying to be very MVVM

Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Using Keys to call Commands
Reply #1 - Sep 25th, 2018 at 4:08pm
Print Post  
The control raises VirtualKeyboard.KeyPressed event when keys are pressed. Maybe try directly executing your commands from the handler, or set the value of some attached property to the key code and then use data triggers from the style.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
DavidM
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 2
Joined: Aug 13th, 2018
Re: Using Keys to call Commands
Reply #2 - Sep 26th, 2018 at 9:09am
Print Post  
Thanks Slavcho,
Datatriggers is was im looking for... however, how can i pin-point a specific Key in a style?...
from the Samples i can only see a
Code
Select All
 DataType="{x:Type vk:ExtendedKey} 

but not how to target a Key by (lets say) Name or VirtualKey value...

Thanks
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Using Keys to call Commands
Reply #3 - Sep 26th, 2018 at 12:49pm
Print Post  
You could use data triggers for that too, checking the values of any property listed for respective key class. E.g. if you set custom style for RegularKey, adding following trigger will paint the M key in red. You could as well trigger on Content or VirtualKey values, depending on the key type.

Code
Select All
<DataTrigger Binding="{Binding LowerCase}" Value="m">
	<Setter Property="Fill" Value="Red" TargetName="rectangle"/>
</DataTrigger> 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint