ItemContainerStyle为彩带组
本文关键字:ItemContainerStyle | 更新日期: 2023-09-27 18:08:15
我试图绑定一个RibbonGroup和一对RibbonButtons到我的视图模型以下xaml:
<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到我的视图模型?
A style intended for type 'RibbonButton' cannot be applied to type 'RibbonControl'.
你可以将一个样式放在另一个样式中,并将其应用于每个按钮:
<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>