WPF窗体由小到大最基本的写法
来源:互联网 发布:js插件 编辑:程序博客网 时间:2024/05/21 06:25
1:建立WPF的窗体
<Window x:Class="IShiTong.Project.WpfChart.Common.PanelWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DialogWin" Height="635 " Width="635
" WindowStyle="None"
Name="DW1" Background="#00E86565" AllowsTransparency="True" WindowStartupLocation="CenterScreen" WindowState="Normal">
<Window.Resources>
<!--此样式能去除按钮点击后的虚线框-->
<Style x:Key="MyFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="-2" StrokeThickness="0" Stroke="Red" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Canvas Height="220" Width="200" Canvas.Left="9" Canvas.Top="14" Name="Canvas1" VerticalAlignment="Center">
<!--设置动画-->
<Canvas.RenderTransform>
<TransformGroup>
<ScaleTransform CenterX="100" CenterY="50"></ScaleTransform>
</TransformGroup>
</Canvas.RenderTransform>
<Canvas.Background>
<ImageBrush ImageSource="/IShiTong.Project.WpfChart.Common;component/Images/back.jpg" />
</Canvas.Background>
</Canvas>
</Window>
2:在PanelWindow.xaml.cs中写入基本的动画
/// <summary>
/// PanelWindow.xaml 的交互逻辑
/// </summary>
public partial class PanelWindow : Window
{
System.Windows.Media.Animation.Storyboard storyboard = new Storyboard();
public PanelWindow(System.Drawing.Point pt,System.Drawing.Bitmap backimag)
{
try
{
InitializeComponent();
ImageSource image = Helpers.ChangeBitmapToImageSource(backimag);
Canvas1.Background.SetCurrentValue(ImageBrush.ImageSourceProperty, image);
DW1.Width = Helpers.GetRect().Width;
DW1.Height = Helpers.GetRect().Height;
Animation();
}
catch { }
}
private void Animation()
{
Storyboard.SetTarget(storyboard, Canvas1);
Storyboard.SetTargetProperty(storyboard, new PropertyPath(Grid.OpacityProperty));
var OpacityDoubleAnimation = new DoubleAnimation();
OpacityDoubleAnimation.To = 1;
storyboard.Children.Add(OpacityDoubleAnimation);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending2 = new DoubleAnimation();
dbAscending2.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending2.BeginTime = TimeSpan.FromSeconds(0.05);
dbAscending2.To = 0.2;
storyboard.Children.Add(dbAscending2);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending3 = new DoubleAnimation();
dbAscending3.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending3.BeginTime = TimeSpan.FromSeconds(0.05);
dbAscending3.To = 0.2;
storyboard.Children.Add(dbAscending3);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending4 = new DoubleAnimation();
dbAscending4.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending4.BeginTime = TimeSpan.FromSeconds(0.10);
dbAscending4.To = 0.5;
storyboard.Children.Add(dbAscending4);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending5 = new DoubleAnimation();
dbAscending5.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending5.BeginTime = TimeSpan.FromSeconds(0.10);
dbAscending5.To = 0.5;
storyboard.Children.Add(dbAscending5);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending6 = new DoubleAnimation();
dbAscending6.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending6.BeginTime = TimeSpan.FromSeconds(0.15);
dbAscending6.To = 1;
storyboard.Children.Add(dbAscending6);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending7 = new DoubleAnimation();
dbAscending7.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending7.BeginTime = TimeSpan.FromSeconds(0.15);
dbAscending7.To = 1;
storyboard.Children.Add(dbAscending7);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath(Grid.OpacityProperty));
var OpacityDoubleAnimation1 = new DoubleAnimation();
OpacityDoubleAnimation1.To = 0.2;
storyboard.Children.Add(OpacityDoubleAnimation1);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending8 = new DoubleAnimation();
dbAscending8.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending8.BeginTime = TimeSpan.FromSeconds(0.20);
dbAscending8.To = 1.5;
storyboard.Children.Add(dbAscending8);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending9 = new DoubleAnimation();
dbAscending9.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending9.BeginTime = TimeSpan.FromSeconds(0.20);
dbAscending9.To = 1.5;
storyboard.Children.Add(dbAscending9);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending10 = new DoubleAnimation();
dbAscending10.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending10.BeginTime = TimeSpan.FromSeconds(0.25);
dbAscending10.To = 2;
storyboard.Children.Add(dbAscending10);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending11 = new DoubleAnimation();
dbAscending11.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending11.BeginTime = TimeSpan.FromSeconds(0.25);
dbAscending11.To = 2;
storyboard.Children.Add(dbAscending11);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending12 = new DoubleAnimation();
dbAscending12.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending12.BeginTime = TimeSpan.FromSeconds(0.3);
dbAscending12.To = 4;
storyboard.Children.Add(dbAscending12);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending13 = new DoubleAnimation();
dbAscending13.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending13.BeginTime = TimeSpan.FromSeconds(0.3);
dbAscending13.To = 4;
storyboard.Children.Add(dbAscending13);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending14 = new DoubleAnimation();
dbAscending14.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending14.BeginTime = TimeSpan.FromSeconds(0.35);
dbAscending14.To = 6;
storyboard.Children.Add(dbAscending14);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending15 = new DoubleAnimation();
dbAscending15.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending15.BeginTime = TimeSpan.FromSeconds(0.35);
dbAscending15.To = 6;
storyboard.Children.Add(dbAscending15);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending16 = new DoubleAnimation();
dbAscending16.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending16.BeginTime = TimeSpan.FromSeconds(0.4);
dbAscending16.To = 8;
storyboard.Children.Add(dbAscending16);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending17 = new DoubleAnimation();
dbAscending17.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending17.BeginTime = TimeSpan.FromSeconds(0.4);
dbAscending17.To = 8;
storyboard.Children.Add(dbAscending17);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending18 = new DoubleAnimation();
dbAscending18.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending18.BeginTime = TimeSpan.FromSeconds(0.45);
dbAscending18.To = 10;
storyboard.Children.Add(dbAscending18);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending19 = new DoubleAnimation();
dbAscending19.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending19.BeginTime = TimeSpan.FromSeconds(0.45);
dbAscending19.To = 10;
storyboard.Children.Add(dbAscending19);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending20 = new DoubleAnimation();
dbAscending20.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending20.BeginTime = TimeSpan.FromSeconds(0.50);
dbAscending20.To = 12;
storyboard.Children.Add(dbAscending20);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending21 = new DoubleAnimation();
dbAscending21.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending21.BeginTime = TimeSpan.FromSeconds(0.50);
dbAscending21.To = 12;
dbAscending21.Completed += new EventHandler(dbAscending19_Completed);
storyboard.Children.Add(dbAscending21);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleX"));
DoubleAnimation dbAscending22 = new DoubleAnimation();
dbAscending22.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending22.BeginTime = TimeSpan.FromSeconds(0.55);
dbAscending22.To = 14;
storyboard.Children.Add(dbAscending22);
storyboard.Begin();
Storyboard.SetTargetProperty(storyboard, new PropertyPath("RenderTransform.Children[0].ScaleY"));
DoubleAnimation dbAscending23 = new DoubleAnimation();
dbAscending23.Duration = new Duration(TimeSpan.FromSeconds(0.05));
dbAscending23.BeginTime = TimeSpan.FromSeconds(0.55);
dbAscending23.To = 14;
dbAscending23.Completed += new EventHandler(dbAscending19_Completed);
storyboard.Children.Add(dbAscending19);
storyboard.Begin();
}
private void dbAscending19_Completed(object sender, EventArgs e)
{
Thread.Sleep(200);
this.Close();
}
3.运行即可
- WPF窗体由小到大最基本的写法
- WPF窗体的生命周期
- [WPF]WPF实现MDI窗体的方法
- WPF-009:WPF窗体的拖动
- WPF自定义窗体的实现
- 事务的基本写法
- 基本的模块写法
- CMakeList的基本写法
- WPF窗体
- WPF一个绑定格式化显示的写法
- 禁用WPF窗体的最大化按钮
- WPF实现MDI窗体的方法
- WPF MDI窗体的实现方法
- 【WPF】C#获取运行的窗体标题
- WPF制作自己的模拟窗体
- WPF 如何访问其他窗体的控件
- WPF窗体隐藏鼠标光标的方法
- WPF无边框透明窗体的缩放
- eclipse构建maven的web项目
- 黑马程序员_用户界面
- 以太网自动协商原理
- 国人当自强:两岸三地在线编程学习网站大搜罗
- oracle中WMSYS.WM_CONCAT函数的版本差异
- WPF窗体由小到大最基本的写法
- smarty foreach
- 再看 --Handler sendMessage 与 obtainMessage (sendToTarget)比较
- android 直接打开指定网页
- 最优化--等式约束最优性条件
- js读取json格式
- HttpLive 总结:
- MANAGED & UNMANAGED (DYNAMIC )TEXTURES IN LIBGDX (OPENGL CONTEXT LOSS)
- Android机顶盒 获取当前连接网络的Ip地址