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

C# Avalonia 15- Animation- CachingTest

CachingTest.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="600" Width="800"x:Class="AvaloniaUI.CachingTest"x:Name="window"Title="CachingTest"><Window.Resources><ArithmeticConverter x:Key="converter" /></Window.Resources><Grid Margin="5" RowDefinitions="*,auto"><Canvas Name="canvas"><Path Name="pathBackground" Stroke="DarkRed" StrokeThickness="1" ></Path><Rectangle Name="rect" Canvas.Left="10" Canvas.Top="100" Fill="Blue" Width="75" Height="75"><Rectangle.Styles><Style Selector="Rectangle"><Style.Animations><Animation Duration="0:0:10" IterationCount="Infinite"><KeyFrame Cue="0%"><Setter Property="Canvas.Left" Value="10"/></KeyFrame><KeyFrame Cue="100%"><Setter Property="Canvas.Left"Value="{Binding #window.Width, Converter={StaticResource converter}, ConverterParameter=-100}" /></KeyFrame></Animation></Style.Animations></Style></Rectangle.Styles></Rectangle></Canvas><CheckBox Grid.Row="2" Name="chkCache" Content="Enable Caching"IsChecked="False" Click="chkCache_Click"></CheckBox></Grid>
</Window>

CachingTest.axaml.cs代码

using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using System;
using System.Text;namespace AvaloniaUI;public partial class CachingTest : Window
{public CachingTest(){InitializeComponent();int maxHeight = (int)this.Height;int maxWidth = (int)this.Width;var rand = new Random();var sb = new StringBuilder();// PathGeometry 用字符串构造sb.Append("M 0,0 ");for (int i = 0; i < 500; i++){sb.Append($"L {rand.Next(0, maxWidth)},{rand.Next(0, maxHeight)} ");}var geometry = Geometry.Parse(sb.ToString());pathBackground.Data = geometry;chkCache.Click += chkCache_Click;}private void chkCache_Click(object? sender, RoutedEventArgs e){if (chkCache.IsChecked == true){var rtb = new RenderTargetBitmap(new PixelSize((int)Bounds.Width, (int)Bounds.Height));rtb.Render(pathBackground);pathBackground.Fill = new ImageBrush(rtb);}else{pathBackground.Fill = null; // 移除缓存,恢复原始绘制}}
}

运行效果

 

http://www.jsqmd.com/news/5460/

相关文章:

  • 事务和Spring常用注解的总结
  • 在 Linux 中安装和配置 NTP 服务器和 NTP 客户端
  • Redis 高可用篇 - 实践
  • Ansible + Docker 部署 MinIO 集群
  • ​​万用表与电流探头测量电流信号的技术对比分析​​
  • flink运行时架构 - --
  • WPF Canvas mark triangle, circle, and retangle, then save the whole canvas as jpg file
  • wifi亮灭屏机制--系统修改
  • 自动遍历测试利器:开源工具AppCrawler 配置全解析
  • 得帆云ETL全新版本升级驱动数据高效流转
  • 挖同行墙脚!有稳定供应商的客户怎么下手构建?
  • 开源技术崛起:中国如何构建数字经济时代的创新基础设施
  • 250928
  • 地图商业授权共享 - no
  • DevOps平台选型指南:数字化转型中的技术决策关键
  • window 安全模式卸载任何软件
  • 定制笔记本电脑工厂排名:从基础代工到联合设计全面分析 - 教程
  • 题解:qoj1261 Inv
  • sv 去除字符串行尾空格函数
  • LeetCode 386 字典序排数 Swift 题解:模拟字典翻页的遍历技巧 - 实践
  • 题解:AT_abc214_g [ABC214G] Three Permutations
  • 通过velocity将增量发版的代码及文件生成生成一个linux shell文件(解放运维)
  • 从企业级项目到普惠API:我如何将自研的人脸识别引擎打造成「识度AI」
  • 得帆AI aPaaS 1.0正式发布,低代码+AI关键特性等你探索
  • 【Array】数组:多个值的集合
  • 帮助向量机深度解析:从数学原理到工程实践的完整指南
  • 【Array】类型化数组:强类型集合的优势
  • 2025节能报告咨询机构最新推荐榜单:帮项目方筛选高效节能方案服务机构
  • 详细介绍:DBA | MySQL 数据库基础数据操作学习实践笔记
  • Windows远程桌面出现CredSSP加密数据修正问题解决方案