我正在尝试使用控制模板来自定义WPF中的按钮。我有以下问题:1.鼠标上的按钮颜色不会变为红色2.按下时会产生摆动效果
以下是xaml:-->
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="1"
Padding="4,2"
BorderBrush="DarkGray"
CornerRadius="3"
Background="{StaticResource ButtonDarkColorBrush}">
<Grid >
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" Name="content" Style="{StaticResource ShadowStyle}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter TargetName="border" Property="BorderBrush" Value="#FF4788c8" />-->
<Setter Property="Foreground" Value="#FF4788c8" />
<Setter Property="Background" Value="Red" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="content" Property="RenderTransform" >
<Setter.Value>
<TranslateTransform Y="0.1" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsDefaulted" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="#FF282828" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.7" />
<Setter Property="Foreground" Value="Gray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
请告知感谢
嗨,梅尔斯普林,试试这个代码,它对我有用。
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="2"
Padding="4,2"
BorderBrush="{DynamicResource BlueGradient2}"
CornerRadius="5"
Background="{TemplateBinding Background}">
<Grid >
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
Name="content"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="Red"/>
<Setter Property="BorderBrush" Value="Red"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="BorderBrush" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>