Avalonia UI简单的加载动画

Avalonia UI简单的加载动画

最近学习AvaloniaUI尝试写了一些简单的加载动画,项目地址:Github

动图:

请添加图片描述

下面是一些代码示例:

在这里插入图片描述
axaml:

<UserControl x:Class="LoadingAnimation.Avalonia.Demo.Views.ProgressPage"
             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"
             xmlns:progress="using:LoadingAnimation.Avalonia.Progress"
             d:DesignHeight="450"
             d:DesignWidth="800"
             mc:Ignorable="d">
    <UniformGrid>
        <Border>
            <progress:Progress1 />
        </Border>
        <Border>
            <progress:Progress2 />
        </Border>
        <Border>
            <progress:Progress3 />
        </Border>
        <Border>
            <progress:Progress4 />
        </Border>
        <Border>
            <progress:Progress5 />
        </Border>
        <Border>
            <progress:Progress6 />
        </Border>
    </UniformGrid>
</UserControl>

在这里插入图片描述
axaml:

<UserControl x:Class="LoadingAnimation.Avalonia.Classic.Classic5"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:local="using:LoadingAnimation.Avalonia.Classic"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             d:DesignHeight="450"
             d:DesignWidth="800"
             mc:Ignorable="d">
    <Grid>
        <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock Margin="4" Text="{Binding $parent[local:Classic5].CaptionText}" />
            <Grid x:Name="maskGrid" Background="{StaticResource PrimaryBrush}">
                <TextBlock Margin="4" Foreground="White" Text="Loading..." />
            </Grid>
        </Grid>
    </Grid>
</UserControl>

csharp:

 public partial class Classic5 : ClassicBase
 {
     public Classic5()
     {
         InitializeComponent();
     }

     protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
     {
         base.OnApplyTemplate(e);

         var _animation = new Animation
         {
             Duration = TimeSpan.FromMicroseconds(2000),
             IterationCount = IterationCount.Infinite,
             SpeedRatio = 0.001,
         };
         _animation.Children.Add(new KeyFrame()
         {
             Cue = new Cue(0.0),
             Setters = { new Setter { Property = ClipProperty, Value = new RectangleGeometry() { Rect = new Rect(new Size(0, 28)) } } }
         });
         _animation.Children.Add(new KeyFrame()
         {
             Cue = new Cue(1.0),
             Setters = { new Setter { Property = ClipProperty, Value = new RectangleGeometry() { Rect = new Rect(new Size(100, 28)) } } }
         });

         GeometryAnimator animator = new GeometryAnimator();
         Animation.SetAnimator(_animation.Children[0].Setters[0], animator);
         Animation.SetAnimator(_animation.Children[1].Setters[0], animator);

         _animation.RunAsync(maskGrid);
     }
 }
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Avalonia是一个**跨平台的UI框架,用于创建桌面应用程序**。 以下是一些关于Avalonia的基本信息和学习资源: 1. **什么是Avalonia?**:Avalonia是一个基于WPF XAML的开源UI框架,它允许开发者使用.NET构建跨平台的桌面应用程序。Avalonia支持多种操作系统,包括Windows、Linux和macOS。 2. **准备工作**:在开始使用Avalonia之前,你需要安装相应的开发环境,并配置项目。这通常包括安装.NET SDK和Avalonia工具包。 3. **创建第一个Avalonia应用程序**:你可以通过官方文档或相关教程来创建你的第一个Avalonia应用,这将帮助你理解基本的应用程序结构和开发流程。 4. **XAML基础**:XAML是一种用于定义用户界面的语言,你可以学习如何使用XAML来创建界面布局和实现数据绑定。 5. **控件和样式**:Avalonia提供了丰富的控件库,你可以学习如何使用这些控件以及如何通过样式和模板来自定义它们的外观。 6. **MVVM模式**:MVVM(Model-View-ViewModel)是一种设计模式,用于分离应用程序的业务逻辑和界面表示。学习MVVM将有助于你构建可维护和可测试的应用程序。 7. **导航和多窗口**:了解如何在Avalonia中进行窗口导航和管理多个窗口,这对于构建复杂的桌面应用程序非常重要。 8. **打包和发布应用程序**:最后,你需要学习如何将你的Avalonia应用程序打包和发布,以便用户可以在他们的计算机上安装和使用你的应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不知名君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值