mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-24 02:40:24 +08:00
enhance: reduce CPU usage
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user