我正在 WPF 中开发一个小型扫雷克隆。对于暴露(即未隐藏)的图块,我有以下样式:
<Style x:Key="ExposedTile" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
当用户单击隐藏地雷的图块时,我在代码中设置了地雷的背景颜色:
button.Background = Brushes.OrangeRed;
由于某种原因,而不是整个按钮的背景,只设置了按钮中文本的背景:
我究竟做错了什么?
编辑:当点击矿井按钮时执行此代码:
button.Style = this.Resources["ExposedTile"] as Style;
if (button == explodedMineTile)
button.Background = Brushes.OrangeRed;
else
button.Background = Brushes.DarkOrange;