mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-24 05:35:00 +00:00
fix: memory leak caused by animation
This commit is contained in:
parent
092bf15906
commit
73cfeca8a9
5 changed files with 109 additions and 24 deletions
70
src/Views/PopupRunningStatus.axaml.cs
Normal file
70
src/Views/PopupRunningStatus.axaml.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class PopupRunningStatus : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<string> DescriptionProperty =
|
||||
AvaloniaProperty.Register<PopupRunningStatus, string>(nameof(Description));
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => GetValue(DescriptionProperty);
|
||||
set => SetValue(DescriptionProperty, value);
|
||||
}
|
||||
|
||||
public PopupRunningStatus()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
if (IsVisible)
|
||||
StartAnim();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
StopAnim();
|
||||
base.OnUnloaded(e);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == IsVisibleProperty)
|
||||
{
|
||||
if (IsVisible)
|
||||
StartAnim();
|
||||
else
|
||||
StopAnim();
|
||||
}
|
||||
}
|
||||
|
||||
private void StartAnim()
|
||||
{
|
||||
icon.Content = new Path()
|
||||
{
|
||||
Data = this.FindResource("Icons.Loading") as StreamGeometry,
|
||||
Classes = { "rotating" },
|
||||
};
|
||||
progressBar.IsIndeterminate = true;
|
||||
}
|
||||
|
||||
private void StopAnim()
|
||||
{
|
||||
if (icon.Content is Path path)
|
||||
path.Classes.Clear();
|
||||
icon.Content = null;
|
||||
progressBar.IsIndeterminate = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue