我有一个用C#编写的WPF应用程序。
我做了一个按钮。我改变了背景颜色。
当鼠标悬停在按钮上时,如何更改蓝色?以及如何控制动画/更改时间?
答案 0 :(得分:3)
http://msdn.microsoft.com/en-us/magazine/cc163421.aspx
您需要考虑为按钮创建“样式”。这将在XAML中完成,你会发现Microsoft Expression Blend真正简化了WPF项目大多数方面的设计。
答案 1 :(得分:0)
<Style x:Key="StyleButton" TargetType="{x:Type Button}">
<Setter Property="FontFamily" Value="Tahoma"></Setter>
<Setter Property="Height" Value="50"></Setter>
<Setter Property="Width" Value="100"></Setter>
<Setter Property="Foreground" Value="Blue"></Setter>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0" Color="White"></GradientStop>
<GradientStop Offset="1" Color="Lime"></GradientStop>
<GradientStop Offset="2" Color="Yellow"></GradientStop>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsFocused" Value="True"/>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="Yellow"/>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Color="blue" Offset="0"/>
<GradientStop Color="#CC00FF" Offset="1"/>
<GradientStop Color="#FF00CC" Offset="2"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</MultiTrigger>
</Style.Triggers>
</Style>