@ -129,70 +129,58 @@ namespace Avalonia.Controls
if ( _ root ! = null )
{
_ content = Content as Control ;
if ( _ content = = null )
OnOrientationChanged ( ) ;
if ( _ root ! = null & & _ content ! = null )
{
_ content = new PathIcon ( )
{
Height = DefaultIndicatorSize ,
Width = DefaultIndicatorSize ,
Name = "PART_Icon"
} ;
_ root . Children . Insert ( 0 , _ content ) ;
_ content . VerticalAlignment = Layout . VerticalAlignment . Center ;
_ content . HorizontalAlignment = Layout . HorizontalAlignment . Center ;
_ content . Loaded + = ( s , e ) = >
{
var composition = ElementComposition . GetElementVisual ( _ content ) ;
UpdateContent ( ) ;
}
}
}
if ( composition = = null )
return ;
private void OnContentLoaded ( object? s , RoutedEventArgs e )
{
if ( _ content = = null )
return ;
var composition = ElementComposition . GetElementVisual ( _ content ) ;
var compositor = composition . Compositor ;
composition . Opacity = 0 ;
if ( composition = = null ) return ;
var smoothRotationAnimation
= compositor . CreateScalarKeyFrameAnimation ( ) ;
smoothRotationAnimation . Target = "RotationAngle" ;
smoothRotationAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
smoothRotationAnimation . Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
var compositor = composition . Compositor ;
composition . Opacity = 0 ;
var opacityAnimation
= compositor . CreateScalarKeyFrameAnimation ( ) ;
opacityAnimation . Target = "Opacity" ;
opacityAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
opacityAnimation . Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
var smoothRotationAnimation = compositor . CreateScalarKeyFrameAnimation ( ) ;
smoothRotationAnimation . Target = "RotationAngle" ;
smoothRotationAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
smoothRotationAnimation . Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
var offset Animation = compositor . CreateVector3 KeyFrameAnimation ( ) ;
offset Animation . Target = "Offset " ;
offset Animation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
offset Animation . Duration = TimeSpan . FromMilliseconds ( 1 5 0 ) ;
var opacity Animation = compositor . CreateScalar KeyFrameAnimation ( ) ;
opacity Animation. Target = "Opacity " ;
opacity Animation. InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
opacity Animation. Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
var scaleAnimation
= compositor . CreateVector3KeyFrameAnimation ( ) ;
scaleAnimation . Target = "Scale" ;
scaleAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
scaleAnimation . Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
var offsetAnimation = compositor . CreateVector3KeyFrameAnimation ( ) ;
offsetAnimation . Target = "Offset" ;
offsetAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
offsetAnimation . Duration = TimeSpan . FromMilliseconds ( 1 5 0 ) ;
var animation = compositor . CreateImplicitAnimationCollection ( ) ;
animation [ "RotationAngle" ] = smoothRotationAnimation ;
animation [ "Offset" ] = offsetAnimation ;
animation [ "Scale" ] = scaleAnimation ;
animation [ "Opacity" ] = opacityAnimation ;
var scaleAnimation = compositor . CreateVector3KeyFrameAnimation ( ) ;
scaleAnimation . Target = "Scale" ;
scaleAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" , new LinearEasing ( ) ) ;
scaleAnimation . Duration = TimeSpan . FromMilliseconds ( 1 0 0 ) ;
composition . ImplicitAnimations = animation ;
var animation = compositor . CreateImplicitAnimationCollection ( ) ;
animation [ "RotationAngle" ] = smoothRotationAnimation ;
animation [ "Offset" ] = offsetAnimation ;
animation [ "Scale" ] = scaleAnimation ;
animation [ "Opacity" ] = opacityAnimation ;
UpdateContent ( ) ;
} ;
SetCurrentValue ( ContentProperty , _ content ) ;
}
else
{
RaisePropertyChanged ( ContentProperty , null , Content , Data . BindingPriority . Style , false ) ;
}
}
OnOrientationChanged ( ) ;
composition . ImplicitAnimations = animation ;
UpdateContent ( ) ;
}
@ -229,6 +217,7 @@ namespace Avalonia.Controls
visualizerVisual . Offset = IsPullDirectionVertical ?
new Vector3D ( visualizerVisual . Offset . X , 0 , 0 ) :
new Vector3D ( 0 , visualizerVisual . Offset . Y , 0 ) ;
visual . Offset = visualizerVisual . Offset ;
_ content . InvalidateMeasure ( ) ;
break ;
case RefreshVisualizerState . Interacting :
@ -353,14 +342,27 @@ namespace Avalonia.Controls
}
else if ( change . Property = = ContentProperty )
{
if ( change . OldValue is Control c )
{
c . Loaded - = OnContentLoaded ;
_ root ? . Children . Remove ( c ) ;
}
_ content = change . NewValue as Control ;
if ( _ content ! = null )
{
_ content . Loaded + = OnContentLoaded ;
}
if ( _ root ! = null & & _ content ! = null )
{
_ root . Children . Insert ( 0 , _ content ) ;
_ content . VerticalAlignment = Layout . VerticalAlignment . Center ;
_ content . HorizontalAlignment = Layout . HorizontalAlignment . Center ;
}
UpdateContent ( ) ;
UpdateContent ( ) ;
}
}
else if ( change . Property = = OrientationProperty )
{