diff --git a/demo/Ursa.Demo/Pages/AspectRatioLayoutDemo.axaml b/demo/Ursa.Demo/Pages/AspectRatioLayoutDemo.axaml
index 77691d5..c56ec69 100644
--- a/demo/Ursa.Demo/Pages/AspectRatioLayoutDemo.axaml
+++ b/demo/Ursa.Demo/Pages/AspectRatioLayoutDemo.axaml
@@ -9,8 +9,8 @@
RowDefinitions="Auto,*">
-
+
diff --git a/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayout.cs b/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayout.cs
index b73cb69..5608232 100644
--- a/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayout.cs
+++ b/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayout.cs
@@ -13,13 +13,15 @@ public class AspectRatioLayout : TransitioningContentControl
AvaloniaProperty.Register>(
nameof(Items));
- public static readonly StyledProperty AspectRatioChangeAmbiguityProperty =
+ public static readonly StyledProperty AspectRatioToleranceProperty =
AvaloniaProperty.Register(
- nameof(AspectRatioChangeAmbiguity), 0.2);
+ nameof(AspectRatioTolerance), 0.2);
- public static readonly StyledProperty CurrentAspectRatioModeProperty =
- AvaloniaProperty.Register(
- nameof(CurrentAspectRatioMode));
+ private AspectRatioMode _currentAspectRatioMode;
+
+ public static readonly DirectProperty CurrentAspectRatioModeProperty =
+ AvaloniaProperty.RegisterDirect(
+ nameof(CurrentAspectRatioMode), o => o.CurrentAspectRatioMode);
private readonly Queue _history = new();
@@ -42,7 +44,7 @@ public class AspectRatioLayout : TransitioningContentControl
public AspectRatioMode CurrentAspectRatioMode
{
get => GetValue(CurrentAspectRatioModeProperty);
- set => SetValue(CurrentAspectRatioModeProperty, value);
+ set => SetAndRaise(CurrentAspectRatioModeProperty, ref _currentAspectRatioMode, value);
}
public static readonly StyledProperty AspectRatioValueProperty =
@@ -64,13 +66,13 @@ public class AspectRatioLayout : TransitioningContentControl
set => SetValue(ItemsProperty, value);
}
- public double AspectRatioChangeAmbiguity
+ public double AspectRatioTolerance
{
- get => GetValue(AspectRatioChangeAmbiguityProperty);
- set => SetValue(AspectRatioChangeAmbiguityProperty, value);
+ get => GetValue(AspectRatioToleranceProperty);
+ set => SetValue(AspectRatioToleranceProperty, value);
}
- private void UpdataHistory(bool value)
+ private void UpdateHistory(bool value)
{
_history.Enqueue(value);
while (_history.Count > 3)
@@ -91,7 +93,7 @@ public class AspectRatioLayout : TransitioningContentControl
private AspectRatioMode GetScaleMode(Rect rect)
{
var scale = GetAspectRatio(rect);
- var absA = Math.Abs(AspectRatioChangeAmbiguity);
+ var absA = Math.Abs(AspectRatioTolerance);
var h = 1d + absA;
var v = 1d - absA;
if (scale >= h) return AspectRatioMode.HorizontalRectangle;
@@ -104,14 +106,14 @@ public class AspectRatioLayout : TransitioningContentControl
{
base.OnPropertyChanged(change);
if (change.Property == ItemsProperty ||
- change.Property == AspectRatioChangeAmbiguityProperty ||
+ change.Property == AspectRatioToleranceProperty ||
change.Property == BoundsProperty)
{
if (change.Property == BoundsProperty)
{
var o = (Rect)change.OldValue!;
var n = (Rect)change.NewValue!;
- UpdataHistory(GetAspectRatio(o) <= GetAspectRatio(n));
+ UpdateHistory(GetAspectRatio(o) <= GetAspectRatio(n));
if (!IsRightChanges()) return;
CurrentAspectRatioMode = GetScaleMode(n);
}
diff --git a/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayoutItem.cs b/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayoutItem.cs
index 0f80564..b941fa8 100644
--- a/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayoutItem.cs
+++ b/src/Ursa/Controls/AspectRatioLayout/AspectRatioLayoutItem.cs
@@ -29,42 +29,14 @@ public class AspectRatioLayoutItem : ContentControl
set => SetValue(EndAspectRatioValueProperty, value);
}
-
- private bool _isUseAspectRatioRange;
-
- public static readonly DirectProperty IsUseAspectRatioRangeProperty =
- AvaloniaProperty.RegisterDirect(
- nameof(IsUseAspectRatioRange), o => o.IsUseAspectRatioRange);
-
- public bool IsUseAspectRatioRange
- {
- get => _isUseAspectRatioRange;
- private set => SetAndRaise(IsUseAspectRatioRangeProperty, ref _isUseAspectRatioRange, value);
- }
+ public bool IsUseAspectRatioRange =>
+ !double.IsNaN(StartAspectRatioValue)
+ && !double.IsNaN(EndAspectRatioValue)
+ && !(StartAspectRatioValue > EndAspectRatioValue);
public AspectRatioMode AcceptAspectRatioMode
{
get => GetValue(AcceptScaleModeProperty);
set => SetValue(AcceptScaleModeProperty, value);
}
-
- protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
- {
- base.OnPropertyChanged(change);
- if (change.Property == StartAspectRatioValueProperty ||
- change.Property == EndAspectRatioValueProperty)
- {
- UpdataIsUseAspectRatioRange();
- }
- }
-
- private void UpdataIsUseAspectRatioRange()
- {
- if (double.IsNaN(StartAspectRatioValue)
- || double.IsNaN(EndAspectRatioValue)
- || StartAspectRatioValue > EndAspectRatioValue)
- IsUseAspectRatioRange = false;
- else
- IsUseAspectRatioRange = true;
- }
}
\ No newline at end of file