当前位置: 首页 > news >正文

C# Avalonia 15- Animation- CodeAnimation

例子展现了两种设置动画的方法,各位自行选择。

 CodeAnimation.axaml代码

<Window xmlns="https://github.com/avaloniaui"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"Height="369.6" Width="454.4"x:Class="AvaloniaUI.CodeAnimation"Title="CodeAnimation"><Grid RowDefinitions="*,*,*"><Button Padding="10" Name="cmdGrow" Click="cmdGrow_Click" Height="40" Width="160"HorizontalAlignment="Center"VerticalAlignment="Center"HorizontalContentAlignment="Center"        VerticalContentAlignment="Center">Click and Make Me Grow</Button><Button Grid.Row="1" Padding="10" Click="cmdShrink_Click"HorizontalAlignment="Center"VerticalAlignment="Center"HorizontalContentAlignment="Center"VerticalContentAlignment="Center">Shrink It Back</Button><Button Grid.Row="2" Padding="10" Name="cmdGrowIncrementally" Click="cmdGrowIncrementally_Click"HorizontalAlignment="Center" VerticalAlignment="Center" Width="240">Click and Make Me Grow (Incrementally)</Button></Grid>
</Window>

CodeAnimation.axaml.cs代码

using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using System;
using System.Reactive.Linq;
using System.Threading;namespace AvaloniaUI;public partial class CodeAnimation : Window
{public CodeAnimation(){InitializeComponent();// 在代码里给按钮设置 TransitioncmdGrow.Transitions = new Transitions{new DoubleTransition{Property = Button.WidthProperty,Duration = TimeSpan.FromSeconds(5),Easing = new SineEaseInOut()},new DoubleTransition{Property = Button.HeightProperty,Duration = TimeSpan.FromSeconds(5),Easing = new SineEaseInOut()}};}private void cmdGrow_Click(object? sender, RoutedEventArgs e){// 设置目标值,相当于 WPF 的 TocmdGrow.Width = this.Width - 100;cmdGrow.Height = (this.Height - 100) / 3;cmdGrow.GetObservable(Button.WidthProperty).Subscribe(v =>{if (v == this.Width - 100){Console.WriteLine("Completed");}});}private void cmdShrink_Click(object? sender, RoutedEventArgs e){cmdGrow.Width = 160;cmdGrow.Height = 40;}private void cmdGrowIncrementally_Click(object? sender, RoutedEventArgs e){var animation = new Animation{Duration = TimeSpan.FromSeconds(0.5),Children ={new KeyFrame{Cue = new Cue(1),Setters ={new Setter(Button.WidthProperty, cmdGrowIncrementally.Width + 10)}}},FillMode = FillMode.Forward};_ = animation.RunAsync(cmdGrowIncrementally);}
}

运行效果

image

 

http://www.rkmt.cn/news/5873.html

相关文章:

  • ubuntu 18.04安装mysql 8.0.41
  • C++ std::unordered_set
  • 如何将一个项目同时提交到GitHub和Gitee(码云)上
  • 易基因:Nat Genet/IF29:董朝斌团队ChIP-seq等揭示作物株型穗型发育调控新机制 助力表观遗传育种驯化改良(顶刊佳作)
  • Python TensorFlow的CNN-LSTM-GRU集成模型在边缘物联网数据IoT电动汽车充电站入侵检测应用
  • 源码管理—密钥硬编码问题
  • 数据库原理-第二章——关系型数据库
  • TCP协议与wireshark
  • ObjectSense 包与模块:代码组织的艺术
  • 数学之美 第一章读后感
  • 【ABSR出版】第二届农业工程与生物学国际研讨会(ISAEB 2025)
  • 博客皮肤
  • 低轨卫星跟踪对星方式
  • 开源中国社区发布AI赋能2.1版本:打造企业级私有化知识中枢新范式
  • PL/SQL 性能优化指南
  • 支配对
  • DamiBus v1.1.0 发布(给单体多模块解耦)
  • Xcode 26 (17A324) 正式版发布 - Apple 平台 IDE
  • macOS Tahoe 26 (25A354) Boot ISO 原版可引导镜像下载
  • macOS Sequoia 15.7 (24G222) 正式版 ISO、IPSW、PKG 下载
  • 【IEEE出版|Fellow云集】第五届电气工程与机电一体化技术国际学术会议(ICEEMT 2025)
  • AR眼镜:远程协作的“破局者”,让困难解决“云手帮”
  • 跨网文件摆渡系统功能全解析
  • Gitee推出跨平台镜像功能:一键同步GitHub仓库,开发者协作效率提升50%
  • MySQL视图定义者和安全性definer/invoker的区别
  • 软件测试day2
  • 软件测式学习
  • 担心安全与速度?这份跨网文件传输方式推荐清单请收好!
  • kettle基本操作3:剪切原字段末尾的空格符
  • Guid g = Guid.Empty;Guid.TryParse(, out g);