功能完善
This commit is contained in:
74
NeuWPF/NeoUI/Controls/Spin.xaml.cs
Normal file
74
NeuWPF/NeoUI/Controls/Spin.xaml.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
namespace NeumUI.Controls;
|
||||
|
||||
using System.Windows;
|
||||
|
||||
using ContentControlBase = System.Windows.Controls.ContentControl;
|
||||
|
||||
/// <summary>
|
||||
/// A spinner for displaying loading state of a page or a section.
|
||||
/// </summary>
|
||||
[TemplateVisualState(Name = "Spun", GroupName = "SpinStates")]
|
||||
[TemplateVisualState(Name = "Unspun", GroupName = "SpinStates")]
|
||||
public class Spin : ContentControlBase
|
||||
{
|
||||
#region Properties
|
||||
public static readonly DependencyProperty IndicatorProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(Indicator),
|
||||
typeof(UIElement),
|
||||
typeof(Spin),
|
||||
new PropertyMetadata(null, OnSpinningChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets element of the spinning indicator.
|
||||
/// </summary>
|
||||
public UIElement Indicator
|
||||
{
|
||||
get => (UIElement)GetValue(IndicatorProperty);
|
||||
set => SetValue(IndicatorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SpinningProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(Spinning),
|
||||
typeof(bool),
|
||||
typeof(Spin),
|
||||
new PropertyMetadata(true, OnSpinningChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets whether spin is spinning.
|
||||
/// </summary>
|
||||
public bool Spinning { get => (bool)GetValue(SpinningProperty);
|
||||
set => SetValue(SpinningProperty, value);
|
||||
}
|
||||
|
||||
private static void OnSpinningChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{ (d as Spin).GoToSpinState(); }
|
||||
|
||||
private void GoToSpinState()
|
||||
{ VisualStateManager.GoToState(this, Spinning && null == Indicator ? "Spun" : "Unspun", true); }
|
||||
|
||||
public static readonly DependencyProperty TipProperty =
|
||||
DependencyProperty.Register(nameof(Tip), typeof(string), typeof(Spin), new PropertyMetadata(string.Empty));
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets customize description content when spin has children.
|
||||
/// </summary>
|
||||
public string Tip { get => (string)GetValue(TipProperty);
|
||||
set => SetValue(TipProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
static Spin()
|
||||
{ DefaultStyleKeyProperty.OverrideMetadata(typeof(Spin), new FrameworkPropertyMetadata(typeof(Spin))); }
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
GoToSpinState();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user