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