【发布时间】:2018-12-03 07:49:21
【问题描述】:
我在 App.xaml 文件中使用波纹管样式。我希望我的按钮(SendCommandBtn)在启用时具有 #5e95a7 颜色,并且没有圆角边框和其他一些样式。
<Style TargetType="{x:Type Button}" x:Key="SendCommandBtn">
<Setter Property="Height" Value="28"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="#5e95a7"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" >
<Border CornerRadius="0" BorderThickness="0" Height="28" Margin="0,0,10,0" >
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="#f2f2f2"/>
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Cursor" Value="No"/>
</Trigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Background" Value="#5e95a7"/>
<Setter Property="Foreground" Value="#fff"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="NormalBtn">
<Setter Property="Background" Value="#5e95a7"/>
<Setter Property="Height" Value="28"/>
<Setter Property="Foreground" Value="#fff"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="#5e95a7"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" >
<Border CornerRadius="0" BorderThickness="0" Background="#5e95a7" Height="28" Margin="0,0,10,0" >
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
现在当我有下面的按钮时:
<Button Name="BtnSIM2" Content=" SIM 2" Grid.Column="2" Click="BtnSIM2_Click" Style="{DynamicResource SendCommandBtn}"></Button>
当按钮启用时,背景颜色为透明,前景为白色。 当按钮再次禁用时,背景是透明的,前景是红色的。 谁能帮我理解我的风格有什么问题?
【问题讨论】:
标签: wpf xaml controltemplate app.xaml