FillBehavior="Stop" // 这个属性会使动画完毕后还原
//-------------改变按钮的背景色为绿色
<Button Content="Button" Height="75" HorizontalAlignment="Left" Margin="27,12,0,0" Name="btnImgBrush" VerticalAlignment="Top" Width="160" Background="LightGray">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="Green"
Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)"
FillBehavior="Stop"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
//-------------改变窗体透明度
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard SpeedRatio="1">
<DoubleAnimation Storyboard.TargetName="element"
Storyboard.TargetProperty="Opacity"
From="0.2" To="1" Duration="0:0:2.5"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Window.Triggers>
//------------让控件透明度渐变
<Trigger Property="IsMouseOver" Value="true">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard Storyboard.TargetProperty="Opacity" Storyboard.TargetName="bg">
<DoubleAnimation From="0" To="0.8" Duration="00:00:00.1" BeginTime="00:00:00"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard Storyboard.TargetProperty="Opacity" Storyboard.TargetName="bg">
<DoubleAnimation From="0.8" To="0" Duration="00:00:00.1" BeginTime="00:00:00"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
无边框窗体增加进入退出动画
<Window.Resources>
<ResourceDictionary>
<Storyboard x:Key="HideWindow">
<DoubleAnimation Duration="0:0:0.1" From="1" To="0" Storyboard.TargetProperty="Opacity" FillBehavior="Stop" />
<DoubleAnimation Duration="0:0:0.1" From="1" To="0.8" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleX)" FillBehavior="Stop" Storyboard.TargetName="MainGrid"/>
<DoubleAnimation Duration="0:0:0.1" From="1" To="0.8" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleY)" FillBehavior="Stop" Storyboard.TargetName="MainGrid"/>
</Storyboard>
<Storyboard x:Key="ShowWindow" >
<DoubleAnimation Duration="0:0:0.1" From="0" To="1" Storyboard.TargetProperty="Opacity" FillBehavior="Stop"/>
<DoubleAnimation Duration="0:0:0.1" From="0.8" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleX)" FillBehavior="Stop" Storyboard.TargetName="MainGrid"/>
<DoubleAnimation Duration="0:0:0.1" From="0.8" To="1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleY)" FillBehavior="Stop" Storyboard.TargetName="MainGrid"/>
</Storyboard>
</ResourceDictionary>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard Storyboard="{StaticResource ShowWindow}"/>
</EventTrigger>
</Window.Triggers>
<Border CornerRadius="2" BorderThickness="1" BorderBrush="#15000000" x:Name="MainGrid" RenderTransformOrigin="0.5,0.5" >
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Border.RenderTransform>
</Border>
private void CloseWindowButton_Click(object sender, RoutedEventArgs e)
{
var story = (Storyboard)this.Resources["HideWindow"];
if (story != null)
{
story.Completed += delegate { Close(); };
story.Begin(this);
}
}
一个云朵的动画文章 image【https://www.cnblogs.com/nimorl/p/9907317.html 】
网友评论