ReversedOrderStackPanel.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. namespace PixiEditor.Helpers.UI
  6. {
  7. public class ReversedOrderStackPanel : StackPanel
  8. {
  9. protected override Size ArrangeOverride(Size arrangeSize)
  10. {
  11. var fHorizontal = Orientation == Orientation.Horizontal;
  12. var rcChild = new Rect(arrangeSize);
  13. var previousChildSize = 0.0;
  14. var children = InternalChildren.Cast<UIElement>().Reverse();
  15. foreach (var child in children)
  16. {
  17. if (child == null)
  18. continue;
  19. if (fHorizontal)
  20. {
  21. rcChild.X += previousChildSize;
  22. previousChildSize = child.DesiredSize.Width;
  23. rcChild.Width = previousChildSize;
  24. rcChild.Height = Math.Max(arrangeSize.Height, child.DesiredSize.Height);
  25. }
  26. else
  27. {
  28. rcChild.Y += previousChildSize;
  29. previousChildSize = child.DesiredSize.Height;
  30. rcChild.Height = previousChildSize;
  31. rcChild.Width = Math.Max(arrangeSize.Width, child.DesiredSize.Width);
  32. }
  33. child.Arrange(rcChild);
  34. }
  35. return arrangeSize;
  36. }
  37. }
  38. }