2

我正在尝试使用以下 xaml 将 RibbonGroup 和几个 RibbonButtons 绑定到我的视图模型:

<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'.
4

1 回答 1

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>
于 2013-04-08T12:45:06.303 回答