diff --git a/src/Views/LoadingIcon.axaml b/src/Views/LoadingIcon.axaml index 929676de..cf1d54fc 100644 --- a/src/Views/LoadingIcon.axaml +++ b/src/Views/LoadingIcon.axaml @@ -5,5 +5,4 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" xmlns:m="using:SourceGit.Models" x:Class="SourceGit.Views.LoadingIcon"> - diff --git a/src/Views/LoadingIcon.axaml.cs b/src/Views/LoadingIcon.axaml.cs index 95f35efa..c7c6fd14 100644 --- a/src/Views/LoadingIcon.axaml.cs +++ b/src/Views/LoadingIcon.axaml.cs @@ -1,6 +1,8 @@ using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.Shapes; using Avalonia.Interactivity; +using Avalonia.Media; namespace SourceGit.Views { @@ -15,13 +17,43 @@ namespace SourceGit.Views protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); - target.Classes.Add("rotating"); + StartAnim(); } protected override void OnUnloaded(RoutedEventArgs e) { + StopAnim(); base.OnUnloaded(e); - target.Classes.Clear(); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsVisibleProperty) + { + if (IsVisible) + StartAnim(); + else + StopAnim(); + } + } + + private void StartAnim() + { + Content = new Path() + { + Data = this.FindResource("Icons.Loading") as StreamGeometry, + Classes = { "rotating" }, + }; + } + + private void StopAnim() + { + if (Content is Path path) + path.Classes.Clear(); + + Content = null; } } }