UserControl 加载动画

1|0效果:实现加载UserControl动画效果

1|1cs代码如下

public class BaseModuleView : UserControl { private TranslateTransform CurTranslate; private DoubleAnimation XAnim; private DoubleAnimation OpacityAnim; private double OriginX = 50; public BaseModuleView() { DoInitAnin(); this.Loaded += BaseModuleView_loaded; this.Unloaded += BaseModuleView_Unloaded; } private void BaseModuleView_Unloaded(object sender, System.Windows.RoutedEventArgs e) { DoUnloadAnim(); } private void BaseModuleView_loaded(object sender, System.Windows.RoutedEventArgs e) { DoLoadAnim(); } private void DoLoadAnim() { this.CurTranslate.BeginAnimation(TranslateTransform.XProperty, XAnim); this.BeginAnimation(UIElement.OpacityProperty, OpacityAnim); } private void DoUnloadAnim() { this.CurTranslate.BeginAnimation(TranslateTransform.XProperty, null); this.BeginAnimation(UIElement.OpacityProperty, null); this.CurTranslate.X = this.OriginX; this.Opacity = 0; } private void DoInitAnin() { CurTranslate = new TranslateTransform(); CurTranslate.X = OriginX; RenderTransform = CurTranslate; Opacity = 0; XAnim = new DoubleAnimation(0, TimeSpan.FromSeconds(0.3)); XAnim.EasingFunction = new ExponentialEase() { EasingMode = EasingMode.EaseInOut }; OpacityAnim = new DoubleAnimation(1, TimeSpan.FromSeconds(0.2)); } }

XAML代码:

<Modules:BaseModuleView x:Class="WFA.OwnUserControlown.EarthDayandnightControl" 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" xmlns:local="clr-namespace:WFA.OwnUserControlown" xmlns:Modules="clr-namespace:WFA.Modules" mc:Ignorable="d" xmlns:local1="clr-namespace:WFA" d:DesignHeight="540" d:DesignWidth="960" > <Grid> </Grid> </Modules:BaseModuleView>

 


__EOF__

本文作者可乐加冰
本文链接https://www.cnblogs.com/zt199510/p/14209814.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   可乐_加冰  阅读(395)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示