我有一个类似
的设置<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>
我的宽度和高度不适用于矩形。我想知道什么是错的
答案 0 :(得分:2)
您需要为自己的样式Key
,然后在代码中引用该键:
<Style x:Key="RectStyle">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
</Style>
然后:
<StackPanel Orientation="Horizontal" >
<Rectangle Fill="{Binding}" Style="{StaticResource RectStyle}" />
</StackPanel>
要将样式应用于某个类型的所有元素,您需要像这样定义它:
<Style TargetType="{x:Type Rectangle}">
如果您想为元素设置多个样式并选择要应用的样式,请使用前者。