l 动画效果
<EventTriggerRoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"To="100" Duration="0:0:1">DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Height"To="50" Duration="0:0:1">DoubleAnimation>
Storyboard>
BeginStoryboard>
EventTrigger>
<EventTriggerRoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"To="200" Duration="0:0:0.5">DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Height"To="30" Duration="0:0:1">DoubleAnimation>
Storyboard>
BeginStoryboard>
EventTrigger>
Style.Triggers>
l 动画渐变效果 以方形为例
<Style x:Key="mybuttonall"TargetType="Button">
<Setter Property="Background"Value="#abcdff">Setter>
<Setter Property="Foreground"Value="#fff">Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.3,0"EndPoint="0.5,1">
<GradientStop Color="#abcdff"Offset="0.1">GradientStop>
<GradientStop Color="#fff"Offset="0.6">GradientStop>
<GradientStop Color="#ffabcd"Offset="0.9">GradientStop>
LinearGradientBrush>
Rectangle.Fill>
Rectangle>
ControlTemplate>
Setter.Value>
Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver"Value="true">Condition>
<Condition Property="IsPressed"Value="false">Condition>
MultiTrigger.Conditions>
<Setter Property="Background"Value="#ff5555">Setter>
MultiTrigger>
<EventTriggerRoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"To="100" Duration="0:0:1">DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Height"To="50" Duration="0:0:1">DoubleAnimation>
Storyboard>
BeginStoryboard>
EventTrigger>
<EventTriggerRoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"To="200" Duration="0:0:0.5">DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="Height"To="30" Duration="0:0:1">DoubleAnimation>
Storyboard>
BeginStoryboard>
EventTrigger>
Style.Triggers>
Style>
l 多线程实现动画lambda
void mybtn_MouseLeave(objectsender,MouseEventArgs e)
{
//创建一个线程使用lambda表达式
Thread threa = newThread(() =>
{
//设定休息的时间
Thread.Sleep(1000);
mybtn.Dispatcher.Invoke(() =>
{
//用代码来触发点击事件
//RoutedEventArgs rea = new RoutedEventArgs();
//鼠标移入事件
MouseEventArgs mea= new MouseEventArgs(Mouse.PrimaryDevice, 0);
//指定触发事件的类型
mea.RoutedEvent= Button.MouseEnterEvent;
mybtn.RaiseEvent(mea);
});
});
threa.Start();
}
///
///鼠标移入
///
///
///
voidmybtn_MouseEnter(object sender,MouseEventArgs e)
{
//创建一个线程使用lambda表达式
Thread threa = newThread(() =>
{
Thread.Sleep(1000);
mybtn.Dispatcher.Invoke(() =>
{
//用代码来触发点击事件
//RoutedEventArgs rea = new RoutedEventArgs();
//鼠标移入事件
MouseEventArgs mea= new MouseEventArgs(Mouse.PrimaryDevice, 0);
//指定触发事件的类型
mea.RoutedEvent= Button.MouseLeaveEvent;
mybtn.RaiseEvent(mea);
});
});
threa.Start();
}