我想在按下按钮时从触发器更改前景,这是我到目前为止的XAML:
<Window.Resources>
<SolidColorBrush x:Key="FocuseBorder" Color="DarkBlue" ></SolidColorBrush>
<SolidColorBrush x:Key="OverBorder" Color="Blue" />
<SolidColorBrush x:Key="PressdBorder" Color="Red" />
<SolidColorBrush x:Key="DefulateBorder" Color="Black" ></SolidColorBrush>
<LinearGradientBrush x:Key="GradDefulat" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF949494" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="GradOver" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF949494" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="GradPressd" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FF666868" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="GradFocuse" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FF5F5F5F" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="SelectionButton3"
TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid Name="grd" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClipToBounds="False">
<Border x:Name="TheBorder" CornerRadius="10"
Background="{StaticResource GradDefulat}" Height="{Binding Path=Height}" Width="{Binding Path=Width}"
BorderBrush="DarkSlateBlue"> </Border>
<Rectangle Name="rect" Fill="{StaticResource GradDefulat}" Stroke="DarkSlateBlue"
Height="200" Width="50">
<Rectangle.RenderTransform >
<RotateTransform Angle="45" CenterX=" 30" CenterY="25" >
</RotateTransform>
</Rectangle.RenderTransform>
</Rectangle>
<ContentPresenter x:Name="ContentArea" VerticalAlignment="Center" HorizontalAlignment="Center "
Content="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
</Grid>
<ControlTemplate.Triggers >
<Trigger Property="IsDefaulted" Value="True">
<Setter TargetName="TheBorder" Property ="Background" Value="{StaticResource GradDefulat}"/>
<Setter TargetName="TheBorder" Property="BorderBrush" Value="{StaticResource DefulateBorder}"/>
<Setter TargetName="rect" Property ="Fill" Value="{StaticResource GradDefulat}"/>
<Setter TargetName="rect" Property="Stroke" Value="{StaticResource DefulateBorder}"/>
</Trigger>
<!-- Defaulated-->
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="TheBorder" Property="Background" Value="{StaticResource GradOver}"/>
<Setter TargetName="TheBorder" Property="BorderBrush" Value="{StaticResource OverBorder}"/>
<Setter TargetName="rect" Property="Fill" Value="{StaticResource GradOver}"/>
<Setter TargetName="rect" Property="Stroke" Value="{StaticResource OverBorder}"/>
</Trigger>
<!-- Over-->
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="TheBorder" Property="Background" Value="{StaticResource GradFocuse}"/>
<Setter TargetName="TheBorder" Property="BorderBrush" Value="{StaticResource FocuseBorder}"/>
<Setter TargetName="rect" Property="Fill" Value="{StaticResource GradFocuse}"/>
<Setter TargetName="rect" Property="Stroke" Value="{StaticResource FocuseBorder}"/>
</Trigger>
<!--Focuse-->
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="TheBorder" Property="Background" Value="{StaticResource GradPressd}"/>
<Setter TargetName="TheBorder" Property="BorderBrush" Value="{StaticResource PressdBorder}"/>
<Setter TargetName="rect" Property="Fill" Value="{StaticResource GradPressd}"/>
<Setter TargetName="rect" Property="Stroke" Value="{StaticResource PressdBorder}"/>
</Trigger>
<!-- Focuse-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
英语不是我的第一语言,所以我为缺乏细节而道歉。