WPF:未应用样式
我有一个设置,比如
<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>
我的宽度和高度不应用于矩形。我想知道怎么了
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为您的样式提供一个
Key
,然后在代码中引用该键:然后:
要使样式应用于您需要定义的类型的所有元素像这样:
如果您想要一个元素有多种样式并选择要应用的样式,请使用前者。
来源
You need to give your style a
Key
and then reference that key in your code:Then:
To get the style to apply to all elements of a type you need to define it like this:
Use the former if you want to have several styles for an element and choose which one you want to apply.
Source