Key shortcut is fired twice

Ribbon for WPF Forum

Posted 13 years ago by Arthur Damen
Version: 10.2.0533
Avatar
Hi,
I have a usercontrol with a button inside that has a shortcut to the <PageDown> key through a command binding.
The purpose is that when the user hits the Pagedown Key, the program shows the next page.

This usercontrol is located on two ribbonbar tabs. When I now hit the Pagedown, Not the next page but the page behind it is shown (2 pages further). That means that when I hit the pagedown, the Event is raised two times, instead of 1. What could I do to prevent that from happening?? The command is shared, so should be used once.

Private Shared MyViewNextPageButton As RibbonCommand = Nothing

  Public Shared ReadOnly Property ViewNextPageButton() As RoutedCommand
    Get
      On Error Resume Next
      If IsNothing(MyViewNextPageButton) Then
        MyViewNextPageButton = New RibbonCommand("ViewNextPageButton", GetType(Ribbon), "Go to Next Page", Nothing, Nothing, "", New InputGestureCollection(New KeyGesture() {New KeyGesture(Key.PageDown, ModifierKeys.None, "Page Down")}))
      End If
      Return MyViewNextPageButton
    End Get
  End Property


<UserControl x:Class="RibbonPageElement"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:commands="clr-namespace:Applications.Designer"
             xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon">
  <Grid>
    <ribbon:Button Name="PageView_NextPage" HorizontalContentAlignment="Center"  Width="30" Command="commands:PADSDesignerCommands.ViewNextPageButton" ></ribbon:Button>
  </Grid>
</UserControl>


Ribbonbar:
            <ribbon:Group Label="Next Page">
              <local:RibbonPageElement x:Name="HomeRibbonPageElement"></local:RibbonPageElement>
            </ribbon:Group>


Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Arthur,

Are you marking the command's executed event as handled?


Actipro Software Support

Posted 13 years ago by Arthur Damen
Avatar
thanks for the help.

Is it always the best way to set the e.handled on true in the procedure?
Could this improve performance?

  Public Sub OnViewNextPageButtonExecute(ByVal sender As Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)
    On Error Resume Next
    'do something 
    e.Handled = True
  End Sub
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Arthur,

If your handlers handle something and there is no need for some other possible handler to also handle it, then sure, it's a good idea to set e.Handled to true. It's preventing other routing code from occurring and from any other handlers that were found from executing, so it may improve performance too.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.