tags:

views:

36

answers:

1

i have a setup like

<ribbon:RibbonGallery>
    <ribbon:RibbonGallery.Resources>
        <Style TargetType="ribbon:RibbonGalleryItem">
            <Setter Property="Width" Value="24" />
            <Setter Property="Padding" Value="0" />
        </Style>
        <Style TargetType="Rectangle">
            <Setter Property="Width" Value="16" />
            <Setter Property="Height" Value="16" />
        </Style>
    </ribbon:RibbonGallery.Resources>

    </ribbon:RibbonGalleryCategory>
    <ribbon:RibbonGalleryCategory x:Name="themeColors" Header="Theme Colors" MinColumnCount="10" MaxColumnCount="10">
        <ribbon:RibbonGalleryCategory.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" >
                    <Rectangle Fill="{Binding}" />
                </StackPanel>
            </DataTemplate>
        </ribbon:RibbonGalleryCategory.ItemTemplate>
    </ribbon:RibbonGalleryCategory>
</ribbon:RibbonGallery>

my width and height are not applied to the rectangles. i wondering whats wrong

+2  A: 

You need to give your style a Key and then reference that key in your code:

    <Style x:Key="RectStyle">
        <Setter Property="Width" Value="16" />
        <Setter Property="Height" Value="16" />
    </Style>

Then:

            <StackPanel Orientation="Horizontal" >
                <Rectangle Fill="{Binding}" Style="{StaticResource RectStyle}" />
            </StackPanel>

To get the style to apply to all elements of a type you need to define it like this:

<Style TargetType="{x:Type Rectangle}">

Use the former if you want to have several styles for an element and choose which one you want to apply.

Source

ChrisF
ooo, but why does the 1st style work? `<Style TargetType="ribbon:RibbonGalleryItem">`. and i just tried, `<Style TargetType="{x:Type Rectangle}">` doesnt work too ...
jiewmeng