WPF编程,通过DoubleAnimation控制图片的透明度,将重叠的图片依次显示。
原文: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控制图片的透明度,将重叠的图片依次显示。的更多相关文章
- javacpp-opencv图像处理之2:实时视频添加图片水印,实现不同大小图片叠加,图像透明度控制,文字和图片双水印
欢迎大家积极开心的加入讨论群 群号:371249677 (点击这里进群) javaCV图像处理系列: javaCV图像处理之1:实时视频添加文字水印并截取视频图像保存成图片,实现文字水印的字体.位置. ...
- WPF编程-WPF体系结构
WPF简介 Windows Presentation Foundation(WPF)是微软新一代图形系统,运行在.NET Framework 3.0架构下,为用户界面.2D/3D 图形.文档和媒体提供 ...
- WPF编程,通过Double Animation动态旋转控件的一种方法。
原文:WPF编程,通过Double Animation动态旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...
- WPF编程,通过Double Animation动态更改控件属性的一种方法。
原文:WPF编程,通过Double Animation动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/a ...
- WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法。
原文:WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330793 ...
- WPF编程,通过Double Animation动态缩放控件的一种方法。
原文:WPF编程,通过Double Animation动态缩放控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/art ...
- WPF编程,窗体最大化、最小化、关闭按钮功能的禁用
原文:WPF编程,窗体最大化.最小化.关闭按钮功能的禁用 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...
- WPF编程,通过Path类型制作沿路径运动的动画一种方法。
原文:WPF编程,通过Path类型制作沿路径运动的动画一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/de ...
- WPF编程,指定窗口图标、窗口标题,使得在运行状态下任务栏显示窗口图标的一种方法。
原文:WPF编程,指定窗口图标.窗口标题,使得在运行状态下任务栏显示窗口图标的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_4330793 ...
随机推荐
- 排错-Ad Hoc Distributed Queries组件被禁用的解决办法
Ad Hoc Distributed Queries组件被禁用的解决办法 by:授客 QQ:1033553122 SQL Server 阻止了对组件 'Ad Hoc Distributed Queri ...
- art-template模板应用
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Expo大作战(四)--快速用expo构建一个app,expo中的关键术语
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...
- Visual Studio Code配置JavaScript环境
一·下载并安装Node.js/Visual Studil Code 下载对应你系统的Node.js版本:https://nodejs.org/en/download/ 选安装目录进行安装 环境配置 · ...
- 使用FireFox插件RESTClient、HttpRequester模拟http(get post)请求
我们写好一个接口后,需要进行测试.有时我们会写一个html表单提交,无疑增加了工作量,尤其是当参数比较多或者传json或xml数据时,效率更是大大降低.我们可以使用基于FireFox的RESTClie ...
- 为什么Sql Server的查询有时候第一次执行很慢,第二次,第三次执行就变快了
老外提问: Hi, I have an sql query which takes 8 seconds in the first run. The next run there after takes ...
- jboss eap6.1(1)
最近决定把公司的项目从jboss3.x迁移出来,先试着摸索一下最新的jboss服务器,从jboss官网上下了一份jboss-eap-6.1,然后找资料准备学习,同时将此次迁移过程记录下来,以备后续复习 ...
- Python中可视化图表处理echarts库的安装
系统环境:Windows 7 企业版 进入cmd 输入:python –m pip install pyecharts
- pt-osc原理、限制、及与原生online-ddl比较
1. pt-osc工作过程 创建一个和要执行 alter 操作的表一样的新的空表结构(是alter之前的结构) 在新表执行alter table 语句(速度应该很快) 在原表中创建触发器3个触发器分别 ...
- windows使用
将桌面.我的文档.收藏夹等转移到其他盘 方法很多,介绍如下: 一.新装的系统,桌面.我的文档.收藏夹等都是默认在C盘的,并且这些数据都是用户经常用到的一些数据.为了避免以后系统崩溃所带来的危险,最好的 ...