我正在尝试使用以下xaml将RibbonGroup和一些RibbonButtons绑定到我的viewmodel:
<Style TargetType="{x:Type ribbon:RibbonGroup}" x:Key="RibbonGroupStyle">
<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="ItemContainerStyle" Value="{DynamicResource RibbonButtonStyle}" />
<Setter Property="ItemsSource" Value="{Binding Buttons}" />
</Style>
<Style TargetType="{x:Type ribbon:RibbonButton}" x:Key="RibbonButtonStyle">
<Setter Property="Label" Value="{Binding Header}" />
</Style>
这给了我以下错误,我可以理解,但是如何正确地将RibbonButton的Label绑定到我的viewmodel?
A style intended for type 'RibbonButton' cannot be applied to type 'RibbonControl'.
答案 0 :(得分:0)
您可以将一种风格放在另一种风格中并将其应用于每个按钮:
<Style TargetType="{x:Type ribbon:RibbonGroup}" x:Key="RibbonGroupStyle">
<Style.Resources>
<Style TargetType="{x:Type ribbon:RibbonButton}" BasedOn="{StaticResource {x:Type ribbon:RibbonButton}">
<Setter Property="Label" Value="{Binding Header}" />
</Style>
</Style.Resources>
<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="ItemsSource" Value="{Binding Buttons}" />
</Style>