wpf Storyboard DoubleAnimation ColorAnimation

复制代码
<Window x:Class="WpfApp24.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp24" WindowState="Maximized"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Button Content="Move Circle" Grid.Row="0" FontSize="30">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="elp"
                                             Storyboard.TargetProperty="(Canvas.Left)"
                                             To="1400" Duration="0:0:5"
                                             AutoReverse="True"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        <Canvas Grid.Row="1">
            <Ellipse x:Name="elp" Fill="Blue" Width="200" Height="200"  Grid.Row="1" Canvas.Left="10"/>
        </Canvas> 
    </Grid>
</Window>
复制代码

 

 

 

 

 

复制代码
<Window x:Class="WpfApp25.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp25"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"> 
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0" Content="Animate Color" Margin="4">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation To="Red" Duration="0:0:5"
                                            Storyboard.TargetName="g1"
                                            Storyboard.TargetProperty="Color"
                                            AutoReverse="True"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
        <Canvas Grid.Row="1">
            <Rectangle x:Name="rect" Canvas.Left="20" Width="1400" Height="800">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="1,0">
                        <GradientStop Offset="0" Color="Yellow"/>
                        <GradientStop Offset="1" Color="Black" x:Name="g1"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </Canvas> 
    </Grid>
</Window>
复制代码

 

 

 

 

 

posted @   FredGrit  阅读(24)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示