【发布时间】:2010-11-22 23:45:43
【问题描述】:
为什么以下样式不起作用?我在其他地方有完全相同的构造,但控件不同,并且可以正常工作。
使用TargetType="{x:Type Separator}" 代替TargetType="Separator" 也不起作用。既不会在 XAML 层次结构中移动 Style 上层。我可以避免使用x:Key="styleName" 和Style="{StaticResource styleName}" 吗?
但更重要的是,我试图理解为什么这种样式绑定并不总是有效。
<ToolBar Height="25">
<ToolBar.Resources>
<Style TargetType="Separator">
<Setter Property="Margin" Value="15"/>
</Style>
<Style TargetType="RadioButton">
<Setter Property="Margin" Value="10"/>
<Setter Property="Width" Value="50"/>
</Style>
</ToolBar.Resources>
<RadioButton Content="A"/> <!-- NOT APPLIED HERE -->
<Separator/> <!-- NOT APPLIED HERE -->
<RadioButton Content="B"/> <!-- NOT APPLIED HERE -->
</ToolBar>
【问题讨论】: