Arranges child elements within a panel into a stack.
        public void ShouldArrangeHorizontally()
        {
            var canvas = GetCanvas();
            var arranger = new StackArranger(canvas.Children, Orientation.Horizontal);

            var size = new Size(800, 200);
            List<ElementBounds> layout;
            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            layout[0].Bounds.Left.ShouldBe(0.0);
            layout[1].Bounds.Left.ShouldBe(100.0);
            layout[2].Bounds.Left.ShouldBe(200.0);

            foreach (FrameworkElement child in canvas.Children)
            {
                child.Margin = new Thickness(5);
            }

            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            layout[0].Bounds.Left.ShouldBe(0.0);
            layout[1].Bounds.Left.ShouldBe(110.0);
            layout[2].Bounds.Left.ShouldBe(220.0);
        }
        public DraggableStackPanel()
        {
            // Setup initial conditions.
            arranger=new StackArranger(
                                    Children, 
                                    Orientation, 
                                    null,
                                    ArrangeChild);

            // Wire up events.
//            SizeChanged += delegate { ArrangeChildren(); };
            LayoutUpdated += delegate { ArrangeChildren(); };
            Loaded += HandleLoaded;
        }
        public void ShouldStretchToFit()
        {
            var canvas = GetCanvas();
            var arranger = new StackArranger(canvas.Children, Orientation.Vertical);

            var size = new Size(200, 800);
            List<ElementBounds> layout;
            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            // Not stretching.
            layout[0].Bounds.Width.ShouldBe(100.0);
            layout[1].Bounds.Width.ShouldBe(100.0);
            layout[2].Bounds.Width.ShouldBe(100.0);

            foreach (FrameworkElement child in canvas.Children)
            {
                child.Width = double.NaN;
            }

            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            layout[0].Bounds.Width.ShouldBe(200.0);
            layout[1].Bounds.Width.ShouldBe(200.0);
            layout[2].Bounds.Width.ShouldBe(200.0);

            // Horizontal
            arranger.Orientation = Orientation.Horizontal;
            size = new Size(800, 200);
            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            layout[0].Bounds.Height.ShouldBe(100.0);
            layout[1].Bounds.Height.ShouldBe(100.0);
            layout[2].Bounds.Height.ShouldBe(100.0);

            foreach (FrameworkElement child in canvas.Children)
            {
                child.Height = double.NaN;
            }

            arranger.Measure(size);
            arranger.ArrangeCalculate(size, out layout);

            layout[0].Bounds.Height.ShouldBe(200.0);
            layout[1].Bounds.Height.ShouldBe(200.0);
            layout[2].Bounds.Height.ShouldBe(200.0);
        }