changeset 121:8f94475d3146 tip

final code
author stevenh7776
date Thu, 31 May 2012 15:35:26 +0100
parents 48c389520e5d
children
files OverlapStackPanelDemo/OverlapStackPanelDemo/MainPage.xaml OverlapStackPanelDemo/OverlapStackPanelDemo/OverlapStackPanel.cs OverlapStackPanelDemo/packages/repositories.config
diffstat 3 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/OverlapStackPanelDemo/OverlapStackPanelDemo/MainPage.xaml	Thu May 31 14:12:43 2012 +0100
+++ b/OverlapStackPanelDemo/OverlapStackPanelDemo/MainPage.xaml	Thu May 31 15:35:26 2012 +0100
@@ -9,8 +9,15 @@
              mc:Ignorable="d">
 
     <Grid x:Name="LayoutRoot" Background="White">
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="auto" />
+        </Grid.ColumnDefinitions>
         <StackPanel>
-            <local:OverlapStackPanel Orientation="Vertical">
+            <local:OverlapStackPanel LeftOffset="10"
+                                     Orientation="Vertical"
+                                     Overlap="90"
+                                     Rotation="355"
+                                     UpperOffset="10">
                 <Rectangle Width="100"
                            Height="100"
                            Fill="Blue" />
@@ -21,7 +28,11 @@
                            Height="100"
                            Fill="Yellow" />
             </local:OverlapStackPanel>
-            <local:OverlapStackPanel Orientation="Horizontal">
+            <local:OverlapStackPanel LeftOffset="10"
+                                     Orientation="Horizontal"
+                                     Overlap="90"
+                                     Rotation="355"
+                                     UpperOffset="10">
                 <Rectangle Width="100"
                            Height="100"
                            Fill="Green" />
@@ -32,7 +43,11 @@
                            Height="100"
                            Fill="Silver" />
             </local:OverlapStackPanel>
-            <local:OverlapStackPanel Orientation="Vertical">
+            <local:OverlapStackPanel LeftOffset="10"
+                                     Orientation="Vertical"
+                                     Overlap="90"
+                                     Rotation="355"
+                                     UpperOffset="10">
                 <Rectangle Width="100"
                            Height="100"
                            Fill="Blue" />
--- a/OverlapStackPanelDemo/OverlapStackPanelDemo/OverlapStackPanel.cs	Thu May 31 14:12:43 2012 +0100
+++ b/OverlapStackPanelDemo/OverlapStackPanelDemo/OverlapStackPanel.cs	Thu May 31 15:35:26 2012 +0100
@@ -39,29 +39,24 @@
             else
                 availableSize.Width = double.PositiveInfinity;
 
-            var totalLeftOffset = LeftOffset;
-            var totalUpperOffset = UpperOffset;
-
             foreach (UIElement child in Children.Where(child => child != null))
             {
                 child.Measure(availableSize);
 
-                totalLeftOffset += LeftOffset * childrenResolved;
-                totalUpperOffset += UpperOffset * childrenResolved;
-
                 if (Orientation == Orientation.Vertical)
                 {
                     desiredSize.Width = LeftOffset + Math.Max(desiredSize.Width, child.DesiredSize.Width);
-                    desiredSize.Height += (child.DesiredSize.Height - Overlap);
+                    desiredSize.Height += UpperOffset + child.DesiredSize.Height - Overlap;
                 }
                 else
                 {
-                    desiredSize.Height = totalUpperOffset + Math.Max(desiredSize.Height, child.DesiredSize.Height);
-                    desiredSize.Width += (child.DesiredSize.Width - Overlap);
+                    desiredSize.Height = UpperOffset + Math.Max(desiredSize.Height, child.DesiredSize.Height);
+                    desiredSize.Width += LeftOffset + child.DesiredSize.Width - Overlap;
                 }
                 childrenResolved++;
             }
 
+            // take into account the first item doesn't overlap
             if (Orientation == Orientation.Vertical)
             {
                 desiredSize.Height += Overlap;
@@ -124,12 +119,8 @@
         
         #region Constructor
 
-        public OverlapStackPanel() : base()
+        public OverlapStackPanel()
         {
-            Overlap = 50;
-            Rotation = 355;
-            UpperOffset = 10;
-            LeftOffset = 10;
         }
 
         #endregion
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OverlapStackPanelDemo/packages/repositories.config	Thu May 31 15:35:26 2012 +0100
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+  <repository path="..\OverlapStackPanelDemo\packages.config" />
+</repositories>
\ No newline at end of file