I have a few default RibbonButton
s:
<RibbonButton x:Name="MouseModeButton" Label="Maus" Click="MouseModeButton_Click"
LargeImageSource="/Images/MainWindow/Mouse.png" />
<RibbonButton x:Name="MarkModeButton" Label="Markieren" Click="MarkModeButton_Click"
LargeImageSource="/Images/MainWindow/Mark.png" />
These buttons are "modes" where only one (the last clicked) is enabled.
I want this enabled RibbonButton
to be highlighted from the other ones - the best thing I could come up with is to set the style as it would be clicked right now.
I tried to google it, but the world of WPF seemd to be abadoned from good googleable solutions in xaml. So how would I set this programmaticly from code behind, when a button is clicked, the style should be like the moment when it is clicked?
You could use the built-in RibbonRadioButton
instead, it does exactly what you want.
<RibbonRadioButton x:Name="MouseModeButton" Label="Maus" Click="MouseModeButton_Click"
LargeImageSource="/Images/MainWindow/Mouse.png" />
<RibbonRadioButton x:Name="MarkModeButton" Label="Markieren" Click="MarkModeButton_Click"
LargeImageSource="/Images/MainWindow/Mark.png" />
You can define mutually exclusive button groups using the GroupName
property, e.g.:
<Ribbon>
<RibbonTab Header="tab">
<RibbonGroup Header="Sample">
<RibbonRadioButton Label="Group 1 - Button 1" GroupName="Group 1"/>
<RibbonRadioButton Label="Group 1 - Button 2" GroupName="Group 1"/>
<RibbonRadioButton Label="Group 1 - Button 3" GroupName="Group 1"/>
<RibbonRadioButton Label="Group 2 - Button 1" GroupName="Group 2"/>
<RibbonRadioButton Label="Group 2 - Button 2" GroupName="Group 2"/>
<RibbonRadioButton Label="Group 2 - Button 3" GroupName="Group 2"/>
</RibbonGroup>
</RibbonTab>
</Ribbon>