原文:WPF编程,通过DoubleAnimation控制图片的透明度,将重叠的图片依次显示。

版权声明:我不生产代码,我只是代码的搬运工。 https://blog.csdn.net/qq_43307934/article/details/87369585

3张图片按照1-3的顺序叠放在面板上,然后依次将图片的透明度由1变化到0。当第1张图片的透明度变为0时显示第2张图片,这样形成了一幅连续的动画。

 

 1、建立窗口在Grid 面板中放置图片

    <Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Name="grid"> </Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Margin="5"
Content="开始"
Click="Buttonstart" />
<Button Grid.Column="1"
Margin="5"
Content="暂停"
Click="ButtonPause" />
<Button Grid.Column="2"
Margin="5"
Content="继续"
Click="ButtonResume"/>
<Button Grid.Column="3"
Margin="5"
Content="停止"
Click="ButtonStop" />
</Grid> </Grid>

2、后台

public partial class Window3 : Window
{
Storyboard story;
private List<Image> imagelist; public Window3()
{
InitializeComponent();
} private void Window_Loaded(object sender, RoutedEventArgs e)
{
story = new Storyboard();
NameScope.SetNameScope(this, new NameScope());
imagelist = new List<Image>(); for (int i = 0; i < 3; i++)
{
string name = "img" + (3 - i);
string strUri;
strUri = string.Format("pack://application:,,,/Photo/{0}.jpg", (3 - i));
Image img = new Image();
img.Name = name;
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(strUri);
myBitmapImage.EndInit();
img.Source = myBitmapImage;
this.RegisterName(name, img);
grid.Children.Add(img);
Grid.SetRow(img, 0);
Grid.SetColumn(img, 0);
imagelist.Add(img);
}
imagelist.Reverse();
for (int i = 0; i < imagelist.Count - 1; i++)
{
DoubleAnimation anim = new DoubleAnimation();
anim.BeginTime = TimeSpan.FromSeconds(0.9 * i);
anim.From = 1;
anim.To = 0;
// anim.AutoReverse = true;
anim.RepeatBehavior = RepeatBehavior.Forever;
anim.Duration = TimeSpan.FromSeconds(0.5);
Storyboard.SetTargetName(anim, imagelist[i].Name);
Storyboard.SetTargetProperty(anim, new PropertyPath(Image.OpacityProperty));
story.Children.Add(anim);
} } private void Buttonstart(object sender, RoutedEventArgs e)
{
story.Begin(this, true);
} private void ButtonPause(object sender, RoutedEventArgs e)
{
story.Pause(this);
} private void ButtonResume(object sender, RoutedEventArgs e)
{
story.Resume(this);
} private void ButtonStop(object sender, RoutedEventArgs e)
{
story.Stop(this);
}
}

 

WPF编程,通过DoubleAnimation控制图片的透明度,将重叠的图片依次显示。的更多相关文章

  1. javacpp-opencv图像处理之2:实时视频添加图片水印,实现不同大小图片叠加,图像透明度控制,文字和图片双水印

    欢迎大家积极开心的加入讨论群 群号:371249677 (点击这里进群) javaCV图像处理系列: javaCV图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体.位置. ...

  2. WPF编程-WPF体系结构

    WPF简介 Windows Presentation Foundation(WPF)是微软新一代图形系统,运行在.NET Framework 3.0架构下,为用户界面.2D/3D 图形.文档和媒体提供 ...

  3. WPF编程,通过Double Animation动态旋转控件的一种方法。

    原文:WPF编程,通过Double Animation动态旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...

  4. WPF编程,通过Double Animation动态更改控件属性的一种方法。

    原文:WPF编程,通过Double Animation动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/a ...

  5. WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法。

    原文:WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330793 ...

  6. WPF编程,通过Double Animation动态缩放控件的一种方法。

    原文:WPF编程,通过Double Animation动态缩放控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...

  7. WPF编程,窗体最大化、最小化、关闭按钮功能的禁用

    原文:WPF编程,窗体最大化.最小化.关闭按钮功能的禁用 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...

  8. WPF编程,通过Path类型制作沿路径运动的动画一种方法。

    原文:WPF编程,通过Path类型制作沿路径运动的动画一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/de ...

  9. WPF编程,指定窗口图标、窗口标题,使得在运行状态下任务栏显示窗口图标的一种方法。

    原文:WPF编程,指定窗口图标.窗口标题,使得在运行状态下任务栏显示窗口图标的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330793 ...

随机推荐

  1. Postman Google浏览器离线安装Postman插件

    Google浏览器离线安装Postman插件 by:授客 QQ:1033553122 解决无法通打开谷歌web商店安装Postman插件的问题,文章参考网络. 测试环境:ChromeStandalon ...

  2. 常用的第三方模块 Pillow url

    Pillow PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7 ...

  3. react native中的聊天气泡以及timer封装成的发送验证码倒计时

    今天看来情书写的文章,研究了一下大佬写的文章,自己做一点总结. 其实,今天我想把我近期遇到的坑都总结一下:1.goBack的跨页面跳转,又两种方法,一可以像兔哥那样修改navigation源码,二可以 ...

  4. the database needs something to populate existing rows.

    这是我在使用Django进行models编写时的一个错误. 解决办法: 为其指定一个默认值即可 object_id = models.CharField(max_length=50, default= ...

  5. LeetCode题解之 Search in a Binary Search Tree

    1.题目描述 2.问题分析 利用递归遍历二叉查找树. 3.代码 TreeNode* searchBST(TreeNode* root, int val) { if (root == NULL) ret ...

  6. Oracle EBS OPM 发放生产批

    --发放生产批 --created by jenrry DECLARE x_return_status VARCHAR2 (1); l_exception_material_tbl gme_commo ...

  7. 表的垂直拆分和水平拆分-zz

    https://www.kancloud.cn/thinkphp/mysql-design-optimalize/39326 http://www.cnblogs.com/nixi8/tag/mysq ...

  8. jdk1.8配置环境变量

    1. 准备好jdk安装文件,选择地址,假设使用默认地址 2. 安装jdk,此时跳出安装 jre 的地址 3. 等待安装 4.找到安装路径,选择jdk 5. 复制文件夹下的bin 6. 点击我的电脑右键 ...

  9. python 多进程和子进程1

    多进程的缓冲区 #多进程 process.py from multiprocessing import Process,current_process import time def func1(): ...

  10. django —— 邮件

    官方文档 1.11 配置settings.py # QQ邮箱为例, 其他邮箱对应的SMTP配置可查官方 EMAIL_HOST = "smtp.qq.com" EMAIL_PORT ...