设置 RibbonButton 样式,因为它会被点击

Set RibbonButton Style as it would be clicked

我有几个默认的RibbonButtons:

<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" />

这些按钮是“模式”,其中仅启用一个(最后一次单击)。 我希望这个启用的 RibbonButton 从其他的突出显示 - 我能想到的最好的办法是设置样式,因为它会立即被点击。

我尝试 google 它,但 WPF 的世界似乎被 xaml 中好的 google 可行解决方案所抛弃。那么我如何从代码后面以编程方式设置它,当单击按钮时,样式应该像单击按钮时那样?

您可以改用内置的 RibbonRadioButton,它完全符合您的要求。

<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" />

您可以使用GroupName属性定义互斥按钮组,例如:

<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>