fix: SectionPanel resizing

This commit is contained in:
2026-03-05 07:36:17 +03:00
parent a2f99cc376
commit fe46722d55
+6 -8
View File
@@ -94,7 +94,6 @@ public class SectionPanel : Panel
private readonly Dictionary<Control, int> _childIndeces = new Dictionary<Control, int>(); private readonly Dictionary<Control, int> _childIndeces = new Dictionary<Control, int>();
private bool _initialized = false; private bool _initialized = false;
private int _previousIndex = 0; private int _previousIndex = 0;
private bool _isChangingIndex = false;
public SectionPanel() public SectionPanel()
: base() : base()
@@ -105,7 +104,6 @@ public class SectionPanel : Panel
return; return;
panel.CanScrollBackward = panel.Cyclic || panel.CurrentIndex != 0; panel.CanScrollBackward = panel.Cyclic || panel.CurrentIndex != 0;
panel.CanScrollForward = panel.Cyclic || panel.CurrentIndex != panel.Children.Count() - 1; panel.CanScrollForward = panel.Cyclic || panel.CurrentIndex != panel.Children.Count() - 1;
_isChangingIndex = true;
panel.InvalidateArrange(); panel.InvalidateArrange();
}); });
ChildrenSourceProperty.Changed.AddClassHandler<SectionPanel>((panel, ea) => ChildrenSourceProperty.Changed.AddClassHandler<SectionPanel>((panel, ea) =>
@@ -309,22 +307,22 @@ public class SectionPanel : Panel
_initialized = true; _initialized = true;
} }
if (!_isChangingIndex) if (_previousIndex == CurrentIndex)
{
foreach (var (child, i) in _childIndeces) foreach (var (child, i) in _childIndeces)
{ {
var rect = Orientation switch var rect = Orientation switch
{ {
Orientation.Vertical => new Rect(0, (i - _previousIndex) * finalSize.Height, finalSize.Width, finalSize.Height), Orientation.Vertical => new Rect(0, i * finalSize.Height, finalSize.Width, finalSize.Height),
Orientation.Horizontal => new Rect((i - _previousIndex) * finalSize.Width, 0, finalSize.Width, finalSize.Height), Orientation.Horizontal => new Rect(i * finalSize.Width, 0, finalSize.Width, finalSize.Height),
_ => default _ => default
}; };
child.Arrange(rect); child.Arrange(rect);
} }
if (Children.Count() > 1) }
else if (Children.Count() > 1)
Dispatcher.UIThread.Post(async () => _ = ApplyOffset(finalSize, true), DispatcherPriority.Render); Dispatcher.UIThread.Post(async () => _ = ApplyOffset(finalSize, true), DispatcherPriority.Render);
_isChangingIndex = false;
return finalSize; return finalSize;
} }