mirror of
https://github.com/yaobiao131/downkyicore.git
synced 2025-08-10 00:52:31 +00:00
style: 修改部分代码样式
This commit is contained in:
@@ -50,11 +50,11 @@ public class CustomPagerViewModel : INotifyPropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
private int count;
|
||||
private int _count;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return count; }
|
||||
get => _count;
|
||||
set
|
||||
{
|
||||
if (value < Current || value < 0)
|
||||
@@ -65,11 +65,11 @@ public class CustomPagerViewModel : INotifyPropertyChanged
|
||||
}
|
||||
else
|
||||
{
|
||||
count = value;
|
||||
_count = value;
|
||||
|
||||
Visibility = count > 1;
|
||||
Visibility = _count > 1;
|
||||
|
||||
OnCountChanged(count);
|
||||
OnCountChanged(_count);
|
||||
|
||||
SetView();
|
||||
|
||||
@@ -99,7 +99,7 @@ public class CustomPagerViewModel : INotifyPropertyChanged
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isSuccess = OnCurrentChanged(_current, value);
|
||||
var isSuccess = OnCurrentChanged(_current, value);
|
||||
if (isSuccess)
|
||||
{
|
||||
_current = value;
|
||||
@@ -116,7 +116,7 @@ public class CustomPagerViewModel : INotifyPropertyChanged
|
||||
|
||||
public int First
|
||||
{
|
||||
get { return _first; }
|
||||
get => _first;
|
||||
set
|
||||
{
|
||||
_first = value;
|
||||
|
||||
@@ -4,116 +4,106 @@ using Avalonia.Controls.Primitives;
|
||||
|
||||
namespace DownKyi.CustomControl;
|
||||
|
||||
public class Loading: TemplatedControl
|
||||
public class Loading : TemplatedControl
|
||||
{
|
||||
private const string LargeState = ":large";
|
||||
private const string SmallState = ":small";
|
||||
private const string SmallState = ":small";
|
||||
|
||||
private const string InactiveState = ":inactive";
|
||||
private const string ActiveState = ":active";
|
||||
private const string InactiveState = ":inactive";
|
||||
private const string ActiveState = ":active";
|
||||
|
||||
private double _maxSideLength = 10;
|
||||
private double _ellipseDiameter = 10;
|
||||
private Thickness _ellipseOffset = new Thickness(2);
|
||||
private double _maxSideLength = 10;
|
||||
private double _ellipseDiameter = 10;
|
||||
private Thickness _ellipseOffset = new(2);
|
||||
|
||||
static Loading()
|
||||
static Loading()
|
||||
{
|
||||
//DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing),
|
||||
// new FrameworkPropertyMetadata(typeof(ProgressRing)));
|
||||
}
|
||||
|
||||
public Loading()
|
||||
{
|
||||
}
|
||||
|
||||
#region IsActive
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get => GetValue(IsActiveProperty);
|
||||
set => SetValue(IsActiveProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly StyledProperty<bool> IsActiveProperty = AvaloniaProperty.Register<Loading, bool>(nameof(IsActive), defaultValue: true);
|
||||
|
||||
private static void OnIsActiveChanged(AvaloniaObject obj, bool arg2)
|
||||
{
|
||||
((Loading)obj).UpdateVisualStates();
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, double> MaxSideLengthProperty = AvaloniaProperty.RegisterDirect<Loading, double>(nameof(MaxSideLength), o => o.MaxSideLength);
|
||||
|
||||
public double MaxSideLength
|
||||
{
|
||||
get => _maxSideLength;
|
||||
private set => SetAndRaise(MaxSideLengthProperty, ref _maxSideLength, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, double> EllipseDiameterProperty =
|
||||
AvaloniaProperty.RegisterDirect<Loading, double>(nameof(EllipseDiameter), o => o.EllipseDiameter);
|
||||
|
||||
public double EllipseDiameter
|
||||
{
|
||||
get => _ellipseDiameter;
|
||||
private set => SetAndRaise(EllipseDiameterProperty, ref _ellipseDiameter, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, Thickness> EllipseOffsetProperty =
|
||||
AvaloniaProperty.RegisterDirect<Loading, Thickness>(nameof(EllipseOffset), o => o.EllipseOffset);
|
||||
|
||||
public Thickness EllipseOffset
|
||||
{
|
||||
get => _ellipseOffset;
|
||||
private set => SetAndRaise(EllipseOffsetProperty, ref _ellipseOffset, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
double maxSideLength = Math.Min(this.Width, this.Height);
|
||||
double ellipseDiameter = 0.1 * maxSideLength;
|
||||
if (maxSideLength <= 40)
|
||||
{
|
||||
//DefaultStyleKeyProperty.OverrideMetadata(typeof(ProgressRing),
|
||||
// new FrameworkPropertyMetadata(typeof(ProgressRing)));
|
||||
ellipseDiameter += 1;
|
||||
}
|
||||
|
||||
public Loading()
|
||||
EllipseDiameter = ellipseDiameter;
|
||||
MaxSideLength = maxSideLength;
|
||||
EllipseOffset = new Thickness(0, maxSideLength / 2 - ellipseDiameter, 0, 0);
|
||||
UpdateVisualStates();
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == IsActiveProperty)
|
||||
{
|
||||
}
|
||||
|
||||
#region IsActive
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get => (bool)GetValue(IsActiveProperty);
|
||||
set => SetValue(IsActiveProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly StyledProperty<bool> IsActiveProperty =
|
||||
AvaloniaProperty.Register<Loading, bool>(
|
||||
nameof(IsActive),
|
||||
defaultValue: true);
|
||||
|
||||
private static void OnIsActiveChanged(AvaloniaObject obj, bool arg2)
|
||||
{
|
||||
((Loading)obj).UpdateVisualStates();
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, double> MaxSideLengthProperty =
|
||||
AvaloniaProperty.RegisterDirect<Loading, double>(
|
||||
nameof(MaxSideLength),
|
||||
o => o.MaxSideLength);
|
||||
|
||||
public double MaxSideLength
|
||||
{
|
||||
get { return _maxSideLength; }
|
||||
private set { SetAndRaise(MaxSideLengthProperty, ref _maxSideLength, value); }
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, double> EllipseDiameterProperty =
|
||||
AvaloniaProperty.RegisterDirect<Loading, double>(
|
||||
nameof(EllipseDiameter),
|
||||
o => o.EllipseDiameter);
|
||||
|
||||
public double EllipseDiameter
|
||||
{
|
||||
get { return _ellipseDiameter; }
|
||||
private set { SetAndRaise(EllipseDiameterProperty, ref _ellipseDiameter, value); }
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<Loading, Thickness> EllipseOffsetProperty =
|
||||
AvaloniaProperty.RegisterDirect<Loading, Thickness>(
|
||||
nameof(EllipseOffset),
|
||||
o => o.EllipseOffset);
|
||||
|
||||
public Thickness EllipseOffset
|
||||
{
|
||||
get { return _ellipseOffset; }
|
||||
private set { SetAndRaise(EllipseOffsetProperty, ref _ellipseOffset, value); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
double maxSideLength = Math.Min(this.Width, this.Height);
|
||||
double ellipseDiameter = 0.1 * maxSideLength;
|
||||
if (maxSideLength <= 40)
|
||||
{
|
||||
ellipseDiameter += 1;
|
||||
}
|
||||
|
||||
EllipseDiameter = ellipseDiameter;
|
||||
MaxSideLength = maxSideLength;
|
||||
EllipseOffset = new Thickness(0, maxSideLength / 2 - ellipseDiameter, 0, 0);
|
||||
UpdateVisualStates();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == IsActiveProperty)
|
||||
{
|
||||
UpdateVisualStates();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVisualStates()
|
||||
{
|
||||
PseudoClasses.Remove(ActiveState);
|
||||
PseudoClasses.Remove(InactiveState);
|
||||
PseudoClasses.Remove(SmallState);
|
||||
PseudoClasses.Remove(LargeState);
|
||||
PseudoClasses.Add(IsActive ? ActiveState : InactiveState);
|
||||
PseudoClasses.Add(_maxSideLength < 60 ? SmallState : LargeState);
|
||||
}
|
||||
private void UpdateVisualStates()
|
||||
{
|
||||
PseudoClasses.Remove(ActiveState);
|
||||
PseudoClasses.Remove(InactiveState);
|
||||
PseudoClasses.Remove(SmallState);
|
||||
PseudoClasses.Remove(LargeState);
|
||||
PseudoClasses.Add(IsActive ? ActiveState : InactiveState);
|
||||
PseudoClasses.Add(_maxSideLength < 60 ? SmallState : LargeState);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user