4
4
using Avalonia . Desktop . Misc ;
5
5
using Avalonia . Desktop . ViewModels ;
6
6
using Avalonia . Input ;
7
+ using Avalonia . Rendering . Composition ;
8
+ using Avalonia . Rendering . Composition . Animations ;
7
9
using Common . Common . Helpers ;
8
10
using Common . Enums ;
11
+ using Common . Helpers ;
9
12
using Common . Interfaces ;
13
+ using CommunityToolkit . Diagnostics ;
10
14
using CommunityToolkit . Mvvm . Input ;
11
15
using Ports . Ports ;
12
16
using Ports . Providers ;
@@ -24,6 +28,8 @@ public sealed partial class CampaignsControl : UserControl
24
28
private readonly InstalledAddonsProvider _addonsProvider ;
25
29
private readonly BitmapsCache _bitmapsCache ;
26
30
31
+ private ImplicitAnimationCollection ? _implicitAnimations ;
32
+
27
33
public CampaignsControl ( )
28
34
{
29
35
InitializeComponent ( ) ;
@@ -383,13 +389,59 @@ private async void OnCampaignsListDrop(object sender, DragEventArgs e)
383
389
}
384
390
}
385
391
386
- private void ListBox_ContainerPrepared ( object ? sender , Avalonia . Controls . ContainerPreparedEventArgs e )
392
+ private void OnListBoxContainerPrepared ( object ? sender , ContainerPreparedEventArgs e )
393
+ {
394
+ if ( e . Container is ListBoxItem item )
395
+ {
396
+ if ( item . Content is SeparatorItem )
397
+ {
398
+ item . IsHitTestVisible = false ;
399
+ item . Focusable = false ;
400
+ }
401
+ else
402
+ {
403
+ if ( _implicitAnimations != null )
404
+ {
405
+ EnsureImplicitAnimationsAsync ( item ) ;
406
+ }
407
+ }
408
+ }
409
+ }
410
+
411
+ private void OnControlAttachedToVisualTree ( object ? sender , VisualTreeAttachmentEventArgs e )
387
412
{
388
- if ( e . Container is ListBoxItem item &&
389
- item . Content is SeparatorItem )
413
+ if ( _implicitAnimations == null )
390
414
{
391
- item . IsHitTestVisible = false ;
392
- item . Focusable = false ;
415
+ var compositor = ElementComposition . GetElementVisual ( this ) ? . Compositor ;
416
+
417
+ Guard . IsNotNull ( compositor ) ;
418
+
419
+ var offsetAnimation = compositor . CreateVector3KeyFrameAnimation ( ) ;
420
+ offsetAnimation . Target = "Offset" ;
421
+ offsetAnimation . InsertExpressionKeyFrame ( 1.0f , "this.FinalValue" ) ;
422
+ offsetAnimation . Duration = TimeSpan . FromMilliseconds ( 400 ) ;
423
+
424
+ var animationGroup = compositor . CreateAnimationGroup ( ) ;
425
+ animationGroup . Add ( offsetAnimation ) ;
426
+
427
+ _implicitAnimations = compositor . CreateImplicitAnimationCollection ( ) ;
428
+ _implicitAnimations [ "Offset" ] = animationGroup ;
429
+ }
430
+ }
431
+
432
+ private async void EnsureImplicitAnimationsAsync ( Control control )
433
+ {
434
+ for ( int i = 0 ; i < 5 ; i ++ )
435
+ {
436
+ var visual = ElementComposition . GetElementVisual ( control ) ;
437
+
438
+ if ( visual != null )
439
+ {
440
+ visual . ImplicitAnimations = _implicitAnimations ;
441
+ return ;
442
+ }
443
+
444
+ await Task . Delay ( 50 ) . ConfigureAwait ( true ) ;
393
445
}
394
446
}
395
447
}
0 commit comments