Avalonia UI
首页支持GitHub 仓库English Doc
  • 👋欢迎
  • 文档
    • ⚡快速开始
      • IDE 支持
        • JetBrains Rider 设置
      • 使用 Avalonia 开发
        • Model-View-ViewModel 模式(MVVM)
        • 控件和布局
        • 数据绑定
        • 图像和动画
      • Windows
      • UserControls
      • 资产
      • 开发者工具
      • 错误和警告日志
      • 未处理的异常
      • 应用生命周期
    • 🔁数据绑定
      • 数据上下文
      • 变化通知
      • 绑定
      • 编译绑定
      • 与控件绑定
      • 转换绑定值
      • 绑定到命令
      • 绑定到任务和可观察对象
      • 使用代码进行绑定
      • 在控件模板中实现绑定
      • 绑定Classes
      • 创建和绑定到附加属性
      • Data Validation
    • 🎨样式
      • 样式
      • 选择器
      • 资源
      • 疑难解答
    • 🧰控件
      • AutoCompleteBox
      • Border
      • Buttons
        • Button
        • RepeatButton
        • RadioButton
        • ToggleButton
        • ButtonSpinner
        • SplitButton
        • ToggleSplitButton
      • Calendar
      • Canvas
      • Carousel
      • CheckBox
      • ComboBox
      • ContentControl
      • ContextMenu
      • Decorator
      • DataGrid
        • DataGridColumns
      • DatePicker
      • DockPanel
      • Expander
      • Flyouts
      • Grid
      • GridSplitter
      • Image
      • ItemsControl
      • ItemsRepeater
      • LayoutTransformControl
      • ListBox
      • MaskedTextBox
      • Menu
      • NativeMenu
      • NumericUpDown
      • Panel
      • ProgressBar
      • RelativePanel
      • ScrollBar
      • ScrollViewer
      • Separator
      • Slider
      • SplitView
      • StackPanel
      • TabControl
      • TabStrip
      • TextBlock
      • TrayIcon
      • TreeDataGrid
        • Creating a Hierarchical TreeDataGrid
        • Creating a Flat TreeDataGrid
        • TreeDataGrid column types
      • TimePicker
      • TextBox
      • ToolTip
      • TreeView
      • TransitioningContentControl
      • UserControl
      • Viewbox
      • Window
      • WrapPanel
    • 📚模板
      • 数据模板
      • 在代码中创建数据模板
      • 实现 IDataTemplate 接口
    • ✏️自定义控件
      • 控件类别
      • 定义属性
    • 🖱️输入
      • 路由事件
      • 剪贴板
      • 鼠标与触控设备
      • 快捷键
    • 🔑动画
      • 关键帧动画
      • 过渡
      • 页面过渡
    • 📐布局
      • 面板概述
      • Alignment、Margin 和 Padding
      • 创建自定义面板
    • 📦发布/分发
      • macOS
  • API 参考
    • 🗒️命名空间
      • Avalonia
      • Avalonia.Animation
        • Avalonia.Animation.Easings
        • Avalonia.Animation.Animators
      • Avalonia.Collections
      • Avalonia.Controls
      • Avalonia.Data
        • Avalonia.Data.Core.Plugins
        • Avalonia.Data.Core
        • Avalonia.Data.Converters
      • Avalonia.Diagnostics
      • Avalonia.Dialogs
  • 指南
    • 🐣基础
      • XAML 介绍
      • Code-behind
      • MVVM 架构
      • 在UI线程上操作
    • 🤿深入
      • 在树莓派上运行你的应用
      • 在树莓派上运行你的应用(使用Raspbian Lite)
      • ReactiveUI
        • 视图激活机制
        • 路由
        • 数据持久化
        • 绑定到 Sorted/Filtered 数据
    • 👩‍💻👩💻 开发人员指南
      • 🏭从源代码中构建 Avalonia
      • Avalonia 与 WPF 和 UWP 之间的比较
      • Debugging Previewer
      • Debugging the XAML compiler
      • macOS 开发
      • Release Process
      • 维护稳定的分支
  • 教程
    • 📋待办事项应用
    • 📻音乐商店应用
    • 🕸️在浏览器中运行
    • 📱为移动设备开发
  • 杂项
    • 👪社区
    • 🖥️WPF 开发者建议
    • 📋正在使用 Avalonia 的项目
    • ❔常见问题
由 GitBook 提供支持
在本页
  • Defining A Keyframe Animation
  • Triggering Animations
  • KeyFrames
  • Delay
  • Repeat
  • Playback Direction
  • Value fill modes
  • Easings

这有帮助吗?

在GitHub上编辑
  1. 文档
  2. 动画

关键帧动画

Keyframe animations in Avalonia are heavily inspired by CSS Animations. They can be used to animate any number of properties on a control, using any number of keyframes to define the states that each property must pass through. Keyframe animations can run any number of times, in either direction.

Defining A Keyframe Animation

Keyframe animations are applied using styles. They can be defined on any style by adding an Animation object to the Style.Animation property:

<Window xmlns="https://github.com/avaloniaui">
    <Window.Styles>
        <Style Selector="Rectangle.red">
            <Setter Property="Height" Value="100"/>
            <Setter Property="Width" Value="100"/>
            <Setter Property="Fill" Value="Red"/>
            <Style.Animations>
                <Animation Duration="0:0:1"> 
                    <KeyFrame Cue="0%">
                        <Setter Property="Opacity" Value="0.0"/>
                    </KeyFrame>
                    <KeyFrame Cue="100%">
                        <Setter Property="Opacity" Value="1.0"/>
                    </KeyFrame>
                </Animation>
            </Style.Animations>
        </Style>
    </Window.Styles>

    <Rectangle Classes="red"/>
</Window>

Triggering Animations

If the selector isn't conditional then the animation will be triggered when a matching Control is spawned into the visual tree. Otherwise, the animations will run whenever its selector is activated. When the selector no longer matches, the currently running animation will be canceled.

KeyFrames

The KeyFrame objects defines when the target Setter objects should be applied on the target Control, with value interpolation in-between.

The Cue property of an KeyFrame object is based on the Duration of the parent animation and can be an absolute time index (i.e., "0:0:1") or a percent of the animation's Duration (i.e., "0%", "100%"). However, Cue's value should not exceed the Duration specified.

All Animation objects should contain at least one KeyFrame, with a Setter that has target property and value.

Multiple properties can be also animated in a single Animation by adding additional Setter objects on the desired KeyFrame:

<Animation Duration="0:0:1"> 
    <KeyFrame Cue="0%">
        <Setter Property="Opacity" Value="0.0"/>
        <Setter Property="RotateTransform.Angle" Value="0.0"/>
    </KeyFrame>
    <KeyFrame Cue="100%">
        <Setter Property="Opacity" Value="1.0"/>
        <Setter Property="RotateTransform.Angle" Value="90.0"/>
    </KeyFrame>
</Animation>

Delay

You can add a delay in a Animation by defining the desired delay time on its Delay property:

<Animation Duration="0:0:1"
           Delay="0:0:1"> 
    ...
</Animation>

Repeat

You can set the following repeat behaviors on IterationCount property of an Animation.

Value
Description

0 to N

Play N times.

INFINITE

Repeat Indefinitely

Playback Direction

The PlaybackDirection property defines how should the animation be played, including repeats.

The following table describes the possible behaviors:

Value
Description

Normal

The animation is played normally.

Reverse

The animation is played in reverse direction.

Alternate

The animation is played forwards first, then backwards.

AlternateReverse

The animation is played backwards first, then forwards.

Value fill modes

The FillMode property defines whether the first or last interpolated value of an animation persist before or after running an animation and on delays in-between runs.

The following table describes the possible behaviors:

Value
Description

None

Value will not persist after animation nor the first value will be applied when the animation is delayed.

Forward

The last interpolated value will be persisted to the target property.

Backward

The first interpolated value will be displayed on animation delay.

Both

Both Forward and Backward behaviors will be applied.

Easings

Easing functions can be set by setting the name of the desired function to the Animation's Easing property:

<Animation Duration="0:0:1"
           Delay="0:0:1"
           Easing="BounceEaseIn"> 
    ...
</Animation>

You can also add your custom easing function class like this:

<Animation Duration="0:0:1"
           Delay="0:0:1">
    <Animation.Easing>
        <local:YourCustomEasingClassHere/>
    </Animation.Easing> 
    ...
</Animation>

The following list contains the built-in easing functions.

  • LinearEasing (Default)

  • BackEaseIn

  • BackEaseInOut

  • BackEaseOut

  • BounceEaseIn

  • BounceEaseInOut

  • BounceEaseOut

  • CircularEaseIn

  • CircularEaseInOut

  • CircularEaseOut

  • CubicEaseIn

  • CubicEaseInOut

  • CubicEaseOut

  • ElasticEaseIn

  • ElasticEaseInOut

  • ElasticEaseOut

  • ExponentialEaseIn

  • ExponentialEaseInOut

  • ExponentialEaseOut

  • QuadraticEaseIn

  • QuadraticEaseInOut

  • QuadraticEaseOut

  • QuarticEaseIn

  • QuarticEaseInOut

  • QuarticEaseOut

  • QuinticEaseIn

  • QuinticEaseInOut

  • QuinticEaseOut

  • SineEaseIn

  • SineEaseInOut

  • SineEaseOut

上一页动画下一页过渡

最后更新于2年前

这有帮助吗?

The example above animates the target Control as defined by its . It will be run immediately when the control is loaded.

Unlike WPF's Triggers, Animations defined in XAML rely on for their triggering behavior. Selectors can always apply to a control, or they can conditionally apply (for example if the control has a style class appled).

🔑
selector
selectors