过渡
Transitions in Avalonia are also heavily inspired by CSS Animations. They listen to any changes in target property's value and subsequently animates the change according to its parameters. They can be defined on any Control
via Transitions
property:
The above example will listen to changes in the Rectangle
's Opacity
property, and when the value changes, apply a smooth transition from the old value to the new value over 2 seconds.
Transitions can also be defined in any style by using a Setter
with Transitions
as the target property and encapsulating them in a Transitions
object, like so:
Every transition has a Property
, Delay
, Duration
and an optional Easing
property.
Property
refers to a transition's target for listening and animating values upon.
Delay
refers to the amount of time before the transition is applied to the target.
Duration
refers to the amount of time that the transition plays.
The easing functions are the same as those described in Keyframe Animations.
The following transition types are available. The correct type must be used depending on the type of the property being animated.
BoxShadowsTransition
: ForBoxShadows
target propertiesBrushTransition
: ForIBrush
target propertiesColorTransition
: ForColor
target propertiesCornerRadiusTransition
: ForCornerRadius
target propertiesDoubleTransitions
: Fordouble
target propertiesFloatTransitions
: Forfloat
target propertiesIntegerTransitions
: Forint
target propertiesPointTransition
: ForPoint
target propertiesSizeTransition
: ForSize
target propertiesThicknessTransition
: ForThickness
target propertiesTransformOperationsTransition
: ForITransform
target propertiesVectorTransition
: ForVector
target properties
Transitioning Render Transforms
Render transforms applied to controls using CSS-like syntax can be transitioned. The following example shows a Border which rotates 45 degrees when the pointer is hovered over it:
The available transitions are:
translate
translate(10px)
, translate(0px, 10px)
px
translateX
translateX(10px)
px
translateY
translateY(10px)
px
scale
scale(10)
, scale(0, 10)
scaleX
scaleX(10)
scaleY
scaleY(10)
skew
skew(90deg)
, skew(0, 90deg)
deg
, grad
, rad
, turn
skewX
skewX(90deg)
deg
, grad
, rad
, turn
skewY
skewY(90deg)
deg
, grad
, rad
, turn
rotate
rotate(90deg)
deg
, grad
, rad
, turn
matrix
matrix(1,2,3,4,5,6)
Avalonia also supports WPF-style render transforms such asRotateTransform
,ScaleTransform
etc. These transforms cannot be transitioned: always use the CSS-like format if you want to apply a transition to a render transform.
最后更新于