当前位置: 首页 > 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.rkmt.cn/news/13459.html

相关文章:

  • Ansible + Docker 部署 MinIO 集群
  • 自动遍历测试利器:开源工具AppCrawler 配置全解析
  • 250928
  • window 安全模式卸载任何软件
  • 定制笔记本电脑工厂排名:从基础代工到联合设计全面分析 - 教程
  • sv 去除字符串行尾空格函数
  • linux执行yum报错: except KeyboardInterrrupt, e
  • grafana如何添加自定义geoJson地图
  • AI元人文:追问与悟空
  • 2025 年纽扣电池厂家:力源电池以 TWS 适配技术与定制服务,打造多场景电源解决方案
  • AWS SageMaker SDK 完整教程:从零开始云端训练你的模型
  • 反转数字-处理溢出的条件-Java
  • Storm-0501威胁组织利用云技术实施勒索攻击的技术分析
  • US$289 VVDI2 AUDI and 5th IMMO Functions Authorization Service
  • OpenLayers地图交互 -- 章节十三:拖拽旋转交互详解 - 实践
  • Python抖音直播间实时数据获取方案:弹幕、礼物与互动消息全解析 - 教程
  • Gitee企业版MCP Server:开启AI驱动的企业研发新时代
  • kafka-日志收集高效的平台部署任务
  • iOS Xcode16 中删除描述文件 Provisioning Profiles
  • git仓库管理memo
  • 关键领域软件研发知识管理的范式革命:从静态文档到智能图谱的跃迁
  • Discord桌面应用远程代码执行漏洞分析
  • DRL模型训练:原始奖励函数记录以及绘制
  • 【Boolean】布尔值:逻辑判断的基础
  • Modbus RTU TCP 拓扑
  • 借助Aspose.Email,使用 Python 将 EML 转换为 MHTML
  • python+springboot+django/flask的医院食堂订餐系统 菜单发布 在线订餐 餐品管理与订单统计系统 - 教程
  • 计算机网络学习笔记 - 浪矢
  • App Store 上架完整流程解析,iOS 应用发布步骤、ipa 文件上传工具、TestFlight 测试与苹果审核经验
  • 使用 Zig 编写英文数字验证码识别工具