准备4张图片

UI control:

<Grid x:Class="Test1.MainBgAd"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Margin="0" Background="Red"
d:DesignHeight="300" d:DesignWidth="300">
<Grid.Resources>
<Storyboard x:Key="sb1">
<DoubleAnimation From="0" To ="1" Storyboard.TargetName="img" Storyboard.TargetProperty="Opacity" Duration="0:0:4"></DoubleAnimation>
</Storyboard>
</Grid.Resources>
<Grid>
<Image Name="imgBg" Stretch="UniformToFill" Opacity="1" Source="/Test1;component/Assets/MianBgAd/minAd2.jpg" />
<Image Name="img" Stretch="UniformToFill" Opacity="0" Source="/Test1;component/Assets/MianBgAd/minAd1.jpg" /> </Grid>
</Grid>

  

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation; namespace Test1
{
/// <summary>
/// Interaction logic for MainBgAd.xaml
/// </summary>
public partial class MainBgAd : Grid
{
public MainBgAd()
{
InitializeComponent();
loadImags();
sb=Resources["sb1"] as Storyboard;
sb.Completed += new EventHandler(sb_Completed);
Loaded += new RoutedEventHandler(MainBgAd_Loaded); } Storyboard sb;
int pIndex = 1;
int MaxIndex = 3;
List<BitmapImage> imgList = new List<BitmapImage>();
void MainBgAd_Loaded(object sender, RoutedEventArgs e)
{
Start();
} public void Start() { sb.Begin(); } void sb_Completed(object sender, EventArgs e)
{ if (pIndex > MaxIndex)
{
pIndex = 0;
} img.Opacity = 0;
img.Source=imgList[pIndex];
if (pIndex - 1 < 0)
{
imgBg.Source = imgList[MaxIndex]; }
else {
imgBg.Source = imgList[pIndex - 1];
} sb.Begin();
pIndex++; } void loadImags() { for (int i = 1; i <= 4; i++)
{
imgList.Add( new BitmapImage(new Uri("/Assets/MianBgAd/minAd"+i+".jpg", UriKind.RelativeOrAbsolute))); } } }
}

  

调用:

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
gridMain.Children.Insert(0, new MainBgAd());
}

最新文章

  1. xpath定位中starts-with、contains和text()的用法
  2. POJ 2533 Longest Ordered Subsequence LCS O(n*log(n))
  3. Subversion Edge
  4. android view:手势
  5. easyUI validatebox设置值和获取值,以及属性和方法
  6. codeigniter 对数据库的常用操作
  7. c语言排序算法总结
  8. NUnit使用详解(二)
  9. QT程序库
  10. [LeetCode] 179. Largest Number 解题思路
  11. Redis搭建多台哨兵
  12. 精读《React PowerPlug 源码》
  13. 条件结构if
  14. Educational Codeforces Round 48 (Rated for Div. 2)
  15. Codeforces 524E Rooks and Rectangles 线段树
  16. PTA 7-2 是否完全二叉搜索树(30 分) 二叉树
  17. Android开发中遇到的问题(五)——Eclipse导入Android项目出现&quot;Invalid project description overlaps the location of another project&quot;错误的解决办法
  18. 设置iptables NAT出外网
  19. java环境变量 Path 与CLASSPATH
  20. oracle 11G dataguard 恢复

热门文章

  1. 活字格Web应用平台学习笔记 6 - 使用公式
  2. 完美的nginx图片防盗链设置详解
  3. HCTF2018 pwn题复现
  4. webpack中配置Babel
  5. [Swift] Swift笔记
  6. Android 监听手机GPS打开状态
  7. C#中virtual(虚方法)的理解以及和abstract(抽象方法)的区别
  8. Oracle EBS OM 创建订单
  9. 【工具推荐】截图工具 Snipaste
  10. 【转】Java学习---解析Java Servlet工作过程