mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
enhance: reduce CPU usage
This commit is contained in:
parent
b6e087259b
commit
092bf15906
2 changed files with 34 additions and 3 deletions
|
@ -5,5 +5,4 @@
|
|||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
xmlns:m="using:SourceGit.Models"
|
||||
x:Class="SourceGit.Views.LoadingIcon">
|
||||
<Path x:Name="target" Data="{DynamicResource Icons.Loading}"/>
|
||||
</UserControl>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue