Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RibbonSplitButton Command is executed twice

I am using the Ribbons Control Libary from Microsoft for WPF to privide a Ribbon in our WPF Application.

We use Splitbuttons in the following way in the XAML Part:

<r:RibbonSplitButton Label="SplitButtonLabel" LargeImageSource="..." Command="{Binding SplitButtonCommand}">
  <r:RibbonSplitMenuItem Header="Item 1" ImageSource="..." Command="{Binding Command1}"/>
  <r:RibbonSplitMenuItem Header="Item 2" ImageSource="..." Command="{Binding Command2}"/>
  <r:RibbonSplitMenuItem Header="Item 3" ImageSource="..." Command="{Binding Command3}"/>
</r:RibbonSplitButton>

If i click on the Upper Part of the Split Button the Command SplitButtonCommand is executed once as it normally.

If I click on the Bottom Part of the SplitButton and then any Menü Item (e.g. Item 1) the Command of this Item is executed twice.

Does anyone have any clue causes the Problem?

like image 607
sebastianmehler Avatar asked Jan 09 '14 08:01

sebastianmehler


3 Answers

It appears it maybe by design have a look at this article. There is a workaround mentioned:

Although this is the nature of RibbonControl you can try to workaround this by parsing the ExecutedRoutedEventArgs and check if the OriginalSource is the same as Source, if yes then get this command executed.

RibbonMenuItem triggers command twice

like image 188
SWilko Avatar answered Nov 06 '22 19:11

SWilko


Just another workaround, you can use the click event:

<r:RibbonSplitButton Label="SplitButtonLabel" LargeImageSource="..." Click="Split_Click">
  <r:RibbonSplitMenuItem Header="Item 1" ImageSource="..." Click="Click_1"/>
  <r:RibbonSplitMenuItem Header="Item 2" ImageSource="..." Click="Click_2"/>
  <r:RibbonSplitMenuItem Header="Item 3" ImageSource="..." Click="Click_3"/>
</r:RibbonSplitButton>


And inside the click event handler, set the Handled property to true:

private void Click_1(object sender, RoutedEventArgs e)
{
    e.Handled = true;
    ((YourViewModel)DataContext).Command1();
}
like image 32
Ayman Avatar answered Nov 06 '22 18:11

Ayman


As dellywheel says it seems to be that this behavior is by design.

I dealt with the Problem changing my Code like the following Example.

<r:RibbonSplitButton Label="SplitButtonLabel" LargeImageSource="..." Command="{Binding SplitButtonCommand}">
  <r:RibbonButton Label="Item 1" SmallImageSource="..." Command="{Binding Command1}"/>
  <r:RibbonButton Label="Item 2" SmallImageSource="..." Command="{Binding Command2}"/>
  <r:RibbonButton Label="Item 3" SmallImageSource="..." Command="{Binding Command3}"/>
</r:RibbonSplitButton>

I replaced the usage of RibbonSplitMenuItem by using RibbonButtons with a provided SmallImageSource

like image 23
sebastianmehler Avatar answered Nov 06 '22 17:11

sebastianmehler