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?
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
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();
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With