sourcegit/src/Views/LoadingIcon.axaml.cs

60 lines
1.3 KiB
C#
Raw Normal View History

2024-05-30 01:12:28 -07:00
using Avalonia;
using Avalonia.Controls;
2024-05-30 01:28:21 -07:00
using Avalonia.Controls.Shapes;
2024-05-30 01:12:28 -07:00
using Avalonia.Interactivity;
2024-05-30 01:28:21 -07:00
using Avalonia.Media;
2024-05-30 01:12:28 -07:00
namespace SourceGit.Views
{
public partial class LoadingIcon : UserControl
{
public LoadingIcon()
{
IsHitTestVisible = false;
InitializeComponent();
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
2024-05-30 01:28:21 -07:00
StartAnim();
2024-05-30 01:12:28 -07:00
}
protected override void OnUnloaded(RoutedEventArgs e)
{
2024-05-30 01:28:21 -07:00
StopAnim();
2024-05-30 01:12:28 -07:00
base.OnUnloaded(e);
2024-05-30 01:28:21 -07:00
}
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;
2024-05-30 01:12:28 -07:00
}
}
}