Hi,
Assume I have a window and XamMaskedEditor within. I want the window to process my own custom command when user presses F2 button.
The problem is that when XamMaskedEditor is focused , each F2 key press is handled inside the control and my custom command is not executed.
Any ideas how to make it work? I need a way to disable F2 processing in XamMaskedEditor.
Okay, not exactly what I meant , but still worthy to try.
Thanks!
Instead of assigning your Executed handler to the Executed property, try using the PreviewExecuted property in the CommandBinding. Commands are routed in WPF and the Preview commands are called first as they provide the means for tunneling the command from the root parent down to the child. This may be the best way to circumvent the command from reaching the editor before reaching your code. In the ExecutedRoutedEventArgs parameter for your PreviewExecuted handler you can set the property Handled to true to stop the event from tunneling down to the editor. If you do that, keep an eye out for any side-effects. There shouldn't be any. However, it is a good idea anyway anytime you stop an event.
Hi Curtis,
thanks for reply!
The problem is I don't really handle KeyUp or KeyDown events, I'm using CommandBinding with KeyGesture set to specific functional key.
So I have smth. like this:
<UserControl.CommandBindings>
<CommandBinding Command="{x:Static local:Commands.AcceptPaymentCmd}"
CanExecute="Command_CanExecuteWhenTransactionInProgress" Executed="AcceptPayment_Executed"/>
Assume AcceptPaymentCmd has F2 input gesture and the XamMaskedEditor is focused currently. User presses F2 and expects the AcceptPaymentCmd to be executed. But instead, the command inside XamMaskedEditor is executed.
Is the only workaround for me will be to subscribe to Preview event and manually call command execution?
It is not a good way in my case.
Hello,
Fortunately, WPF provides routed event handling. This means you can provide a Preview event handler which will intercept an event before it tunnels down to the child element which the event is intended for. There is a Handled property in the event arguments which you can set to true to stop the event from continuing on its trek. Whatever event you are using for handle the F2 key action, look for a Preview version of the event and try handling that.
Thanks,