Advertisement
FrayxRulez

Untitled

Sep 16th, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1.     public class WrapStackPanel : Panel
  2.     {
  3.         protected override Size MeasureOverride(Size availableSize)
  4.         {
  5.             var width = availableSize.Width >= 501 ? availableSize.Width / 2d : availableSize.Width;
  6.             var height1 = 0d;
  7.             var height2 = 0d;
  8.  
  9.             for (int i = 0; i < Children.Count; i++)
  10.             {
  11.                 var child = Children[i];
  12.                 child.Measure(new Size(width, double.PositiveInfinity));
  13.  
  14.                 if (i % 2 == 1 && availableSize.Width >= 501)
  15.                 {
  16.                     height2 += child.DesiredSize.Height;
  17.                 }
  18.                 else
  19.                 {
  20.                     height1 += child.DesiredSize.Height;
  21.                 }
  22.             }
  23.  
  24.             return new Size(availableSize.Width, Math.Max(height1, height2));
  25.         }
  26.  
  27.         protected override Size ArrangeOverride(Size finalSize)
  28.         {
  29.             var width = finalSize.Width >= 501 ? finalSize.Width / 2d : finalSize.Width;
  30.             var height1 = 0d;
  31.             var height2 = 0d;
  32.  
  33.             for (int i = 0; i < Children.Count; i++)
  34.             {
  35.                 var child = Children[i];
  36.                 var x = (i % 2 == 1 && finalSize.Width >= 501) ? width : 0;
  37.                 var y = (i % 2 == 1 && finalSize.Width >= 501) ? height2 : height1;
  38.  
  39.                 child.Arrange(new Rect(x, y, width, child.DesiredSize.Height));
  40.  
  41.                 if (i % 2 == 1 && finalSize.Width >= 501)
  42.                 {
  43.                     height2 += child.DesiredSize.Height;
  44.                 }
  45.                 else
  46.                 {
  47.                     height1 += child.DesiredSize.Height;
  48.                 }
  49.             }
  50.  
  51.             return new Size(finalSize.Width, Math.Max(height1, height2));
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement