2

次のxamlを使用して、RibbonGroupといくつかのRibbonButtonをビューモデルにバインドしようとしています:

<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

1 つのスタイルを別のスタイル内に配置して、すべてのボタンに適用できます。

<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 に答える