0
本来我有一个按钮,并运行良好。现在我想转弯。按钮的bordesr是不可见的,没有背景颜色
<Button Content="Start" x:Name="Start" Style="{StaticResource RoundButtonTemplate}"
HorizontalAlignment="Left"
Margin="20,20,0,0"
VerticalAlignment="Top"
Width="75"
Click="Start_Click">
在后面的代码,我设置背景色为:
Start.IsEnabled = false;
Start.Background = Brushes.Red;
在App.xaml中:
<Application.Resources>
<Style x:Key="RoundButtonTemplate" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="15" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">
</ContentPresenter>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
现在的问题是:
- 背景颜色消失了。
- 按钮的边框不可见。
如何修改样式?
摆脱你的codebehind,添加'背景'和'IsEnabled'和'BorderBrush'到你的风格模板与默认设置,你会完成所有工作,并有做得正确。它不按预期的方式工作。 – 2014-11-25 14:43:38
@ ChrisW.But我想通过不同的条件在代码中动态地更改'Background'和'IsEnabled'。我只是想让边界转弯,就是这样。 – 2014-11-25 14:47:53