Wpf 资源中的按钮样式未应用于按钮
有人能给我解释一下为什么这样不行吗?工具栏中的按钮未获得黑色边框笔刷属性设置。我尝试过TargetType=“Button”和TargetType=“{x:Type Button}”,但都不起作用。我为一系列标签做了几乎完全相同的事情,效果很好。我是WPF的新手。这里有什么我不理解的关于风格优先的地方吗?谢谢Wpf 资源中的按钮样式未应用于按钮,wpf,Wpf,有人能给我解释一下为什么这样不行吗?工具栏中的按钮未获得黑色边框笔刷属性设置。我尝试过TargetType=“Button”和TargetType=“{x:Type Button}”,但都不起作用。我为一系列标签做了几乎完全相同的事情,效果很好。我是WPF的新手。这里有什么我不理解的关于风格优先的地方吗?谢谢 ...Window Definition... <Grid> <Grid.Resources> <Style TargetType=
...Window Definition...
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="BorderBrush" Value="Black" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ToolBar Grid.Column="0" Grid.Row="0" Margin="0">
<Button>
<StackPanel Orientation="Horizontal" Height="Auto">
<Rectangle Width="16" Height="16" Fill="LightBlue" VerticalAlignment="Center"></Rectangle>
<Label Padding="0" VerticalAlignment="Center" HorizontalAlignment="Left">Redraw</Label>
</StackPanel>
</Button>
... More Buttons ...
</ToolBar>
</Grid>
... End Window Definition ...
…窗口定义。。。
重画
... 更多按钮。。。
... 结束窗口定义。。。
给你
<Style x:Key="{x:Static ToolBar.ButtonStyleKey}"
TargetType="{x:Type Button}">
<Setter Property="BorderBrush"
Value="Black" />
</Style>
从
工具栏定义ResourceKey对象,以指定工具栏中控件的样式。要设置工具栏中控件的样式,请将样式的x:key属性设置为工具栏中定义的ResourceKey
工具栏定义以下ResourceKey对象:
- 按钮样式键
- CheckBoxStyleKey
- ComboBoxStyleKey
- 菜单样式键
- RadioButtonStyleKey
- 分隔键
- TextBoxStyleKey
- ToggleButtonStyleKey