fix: SectionPanel resizing

This commit is contained in:
2026-02-27 10:48:47 +03:00
parent 64fa8090dc
commit 79dc2274be
+46 -10
View File
@@ -241,6 +241,40 @@ public class SectionPanel : Panel
InvalidateArrange(); InvalidateArrange();
} }
protected override void OnSizeChanged(SizeChangedEventArgs e)
{
if (!_initialized ||
e.PreviousSize.Width == 0 ||
e.PreviousSize.Height == 0)
{
base.OnSizeChanged(e);
return;
}
Console.WriteLine($"{e.NewSize} {e.PreviousSize}");
foreach (var (child, i) in _childIndeces)
{
var transform = child.RenderTransform as TranslateTransform;
if (transform is null)
{
transform = new TranslateTransform();
child.RenderTransform = transform;
}
Console.WriteLine($"{i} {transform}");
if (child.RenderTransformOrigin != RelativePoint.TopLeft)
child.RenderTransformOrigin = RelativePoint.TopLeft;
_ = Orientation switch
{
Orientation.Vertical => transform.Y += transform.Y == 0 ? 0 : e.PreviousSize.Height - e.NewSize.Height,
Orientation.Horizontal => transform.X += transform.X == 0 ? 0 : e.PreviousSize.Width - e.NewSize.Width,
_ => 0
};
Console.WriteLine($"{i} {transform}");
}
base.OnSizeChanged(e);
}
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
foreach (var child in Children) foreach (var child in Children)
@@ -252,19 +286,21 @@ public class SectionPanel : Panel
if (!_initialized) if (!_initialized)
{ {
foreach (var (i, child) in Children.Enumerate()) foreach (var (i, child) in Children.Enumerate())
{
var rect = Orientation switch
{
Orientation.Vertical => new Rect(0, i * finalSize.Height, finalSize.Width, finalSize.Height),
Orientation.Horizontal => new Rect(i * finalSize.Width, 0, finalSize.Width, finalSize.Height),
_ => default
};
_childIndeces.Add(child, i); _childIndeces.Add(child, i);
child.Arrange(rect);
}
_initialized = true; _initialized = true;
} }
else if (Children.Count() > 1)
foreach (var (child, i) in _childIndeces)
{
var rect = Orientation switch
{
Orientation.Vertical => new Rect(0, i * finalSize.Height, finalSize.Width, finalSize.Height),
Orientation.Horizontal => new Rect(i * finalSize.Width, 0, finalSize.Width, finalSize.Height),
_ => default
};
child.Arrange(rect);
}
if (Children.Count() > 1)
Dispatcher.UIThread.Post(async () => _ = ApplyOffset(finalSize, true), DispatcherPriority.Render); Dispatcher.UIThread.Post(async () => _ = ApplyOffset(finalSize, true), DispatcherPriority.Render);
return finalSize; return finalSize;