From 40213047b1cee48144c5a1eee1778ada6f609ca1 Mon Sep 17 00:00:00 2001
From: chr <chrry550@163.com>
Date: 星期四, 07 三月 2024 16:06:08 +0800
Subject: [PATCH] 优化InnerWindow的Resize;

---
 Models/Sequence.cs           |   31 +
 Controls/IconTabItem.cs      |    3 
 Controls/InnerWindow.xaml.cs |  130 +++----
 MainWindow.xaml.cs           |    5 
 Models/Step.cs               |    8 
 UI/WorkControl.xaml.cs       |  504 +++++++++++++++++--------------
 Controls/InnerWindow.xaml    |    1 
 Utils/Resize.cs              |   84 +++-
 Models/Program.cs            |   43 +
 Models/Variable.cs           |   85 ++--
 UI/Test/ProgramList.xaml.cs  |   28 -
 test.xml                     |    8 
 12 files changed, 516 insertions(+), 414 deletions(-)

diff --git a/Controls/IconTabItem.cs b/Controls/IconTabItem.cs
index fef59e2..559eaa5 100644
--- a/Controls/IconTabItem.cs
+++ b/Controls/IconTabItem.cs
@@ -7,7 +7,7 @@
 
 namespace WPFProject.Controls
 {
-    public class IconTabItem : TabItem , INotifyPropertyChanged
+    public class IconTabItem : TabItem, INotifyPropertyChanged
     {
         public event PropertyChangedEventHandler PropertyChanged;
 
@@ -44,7 +44,6 @@
             set => _Body = value;
         }
 
-        private BitmapImage _icon;
         public BitmapImage Icon
         {
             get { return (BitmapImage)GetValue(IconProperty); }
diff --git a/Controls/InnerWindow.xaml b/Controls/InnerWindow.xaml
index 5d57033..293674d 100644
--- a/Controls/InnerWindow.xaml
+++ b/Controls/InnerWindow.xaml
@@ -8,7 +8,6 @@
              mc:Ignorable="d" 
              HorizontalAlignment="Stretch"
              HorizontalContentAlignment="Stretch"
-             SizeChanged="UserControl_SizeChanged"
              MouseLeftButtonDown="Grid_MouseLeftButtonDown"
              Background="#FFF"
              Focusable="True">
diff --git a/Controls/InnerWindow.xaml.cs b/Controls/InnerWindow.xaml.cs
index 6de3db6..6c89b76 100644
--- a/Controls/InnerWindow.xaml.cs
+++ b/Controls/InnerWindow.xaml.cs
@@ -1,4 +1,5 @@
-锘縰sing System;
+锘縰sing HandyControl.Controls;
+using System;
 using System.ComponentModel;
 using System.Runtime.CompilerServices;
 using System.Windows;
@@ -19,7 +20,8 @@
     /// InnerWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
     public partial class InnerWindow : UserControl, INotifyPropertyChanged
-    {
+    {
+        #region INotifyPropertyChanged
         public virtual event PropertyChangedEventHandler PropertyChanged;
 
         protected virtual void RaisePropertyChanged(string name)
@@ -34,41 +36,46 @@
             {
                 RaisePropertyChanged(propertyName);
             }
-        }
-
-        public CanvasPosition canvasPosition;
-
+        }
+        #endregion
+
+        #region 灞炴��
+
+        #region Common
         public DragType DragType { get; set; } = DragType.Canvas;
-
+        public CanvasPosition canvasPosition;
+        private Canvas canvas;
+        public WindowState WindowState { get; set; } = WindowState.Normal;
+        public AdornerDecorator ResizeAdornerDecorator { get => VisualTreeHelper.GetChild(this, 0) as AdornerDecorator; }
+
+        private string _Title;
+        public string Title
+        {
+            get { return _Title; }
+            set => RaiseAndSetIfChanged(ref _Title, value);
+        }
+
         public int Zindex
         {
-            get {
+            get
+            {
                 return Canvas.GetZIndex(this);
             }
             set
             {
                 Canvas.SetZIndex(this, value);
-            } 
-        }
-
-        public AdornerDecorator ResizeAdornerDecorator { get => VisualTreeHelper.GetChild(this, 0) as AdornerDecorator; }
-
-
+            }
+        }
+        #endregion
+
+        #region 浜嬩欢
         public event EventHandler MinEvent;
         public event EventHandler MaxEvent;
         public event EventHandler CloseEvent;
-        public event EventHandler ZIndexEvent;
-
-        public WindowState WindowState { get; set; } = WindowState.Normal;
-
-        private string _Title;
-
-        public string Title
-        {
-            get { return _Title; }
-            set => RaiseAndSetIfChanged(ref _Title, value);
-        }
-
+        public event EventHandler ZIndexEvent;
+        #endregion
+
+        #region DependencyProperty
         public Brush HeaderBackground
         {
             get { return (Brush)GetValue(HeaderBackgroundProperty); }
@@ -87,8 +94,11 @@
 
         public static readonly DependencyProperty HeaderFontColorProperty =
             DependencyProperty.Register("HeaderFontColor", typeof(Brush), typeof(ProgramList),
-                new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 255, 225))));
-
+                new PropertyMetadata(new SolidColorBrush(Color.FromRgb(255, 255, 225))));
+        #endregion
+
+        #endregion
+
         public InnerWindow() : this(null)
         {
 
@@ -105,26 +115,7 @@
 
             DataContext = this;
             InitializeComponent();
-            SizeChanged += InnerWindow_SizeChanged;
             Loaded += InnerWindow_Loaded;
-        }
-
-        private void InnerWindow_SizeChanged(object sender, SizeChangedEventArgs e)
-        {
-            //throw new NotImplementedException();
-        }
-
-        private void InitThumb()
-        {
-            
-        }
-
-        // 鏂瑰舰宸ュ巶      
-        FrameworkElementFactory GetFactory(Brush back)
-        {
-            FrameworkElementFactory fac = new FrameworkElementFactory(typeof(Rectangle));
-            fac.SetValue(Rectangle.FillProperty, back);
-            return fac;
         }
 
         private void InnerWindow_Loaded(object sender, RoutedEventArgs e)
@@ -140,15 +131,9 @@
                 };
             }
             Loaded -= InnerWindow_Loaded;
-        }
-
-        private Canvas canvas;
-
-        private void Button_Click(object sender, RoutedEventArgs e)
-        {
-            Visibility = Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
-        }
-
+        }
+
+        #region 鎷栨嫿绉诲姩鐩稿叧
         private void DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
         {
             switch (DragType)
@@ -194,12 +179,8 @@
         {
             canvasPosition.Top = Canvas.GetTop(this);
             canvasPosition.Left = Canvas.GetLeft(this);
-        }
-
-        private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
-        {
-
-        }
+        }
+        #endregion
 
         /// <summary>
         /// 娣诲姞鍒扮敾甯冧笂
@@ -223,8 +204,23 @@
             }
             Canvas.SetLeft(this, canvasPosition == null ? 0 : canvasPosition.Left);
             Canvas.SetTop(this, canvasPosition == null ? 0 : canvasPosition.Top);
-        }
-
+            canvas.SizeChanged += Canvas_SizeChanged;
+        }
+
+        private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            Size newSize = e.NewSize;
+            Size previousSize = e.PreviousSize;
+
+            double xRate = newSize.Width / previousSize.Width;
+            double yRate = newSize.Height / previousSize.Height;
+
+            Canvas.SetLeft(this, Canvas.GetLeft(this) * xRate);
+            Canvas.SetTop(this, Canvas.GetTop(this) * yRate);
+            this.Width = this.Width * xRate;
+            this.Height = this.Height * yRate;
+        }
+
         private void Min_Click(object sender, RoutedEventArgs e)
         {
             MinEvent?.Invoke(this, null);
@@ -254,12 +250,6 @@
         {
 
         }
-    }
-
-    public class InnerWindowProp : NotifyBase
-    {
-
-
     }
 
     public enum DragType
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index d1cc03f..337c43e 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -2,6 +2,7 @@
 using System.Windows;
 using System.Windows.Media;
 using WPFProject.Events;
+using WPFProject.Utils;
 
 namespace WPFProject
 {
@@ -27,12 +28,12 @@
 
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
-            
+            // Resize.SetIsResizeable(this, true);
         }
 
         private void mainControl_OnTabChange(object sender, RoutedEventArgs e)
         {
-            string ss = "s";
+            
         }
 
         private void Button_Click_2(object sender, RoutedEventArgs e)
diff --git a/Models/Program.cs b/Models/Program.cs
index 9e0f86c..c92cc56 100644
--- a/Models/Program.cs
+++ b/Models/Program.cs
@@ -4,6 +4,7 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Xml.Serialization;
 
 namespace WPFProject.Models
 {
@@ -20,6 +21,16 @@
         }
 
         /// <summary>
+        /// 搴忓垪闆嗗悎
+        /// </summary>
+        private ObservableCollection<Sequence> _Sequences = new ObservableCollection<Sequence>();
+        public ObservableCollection<Sequence> Sequences
+        {
+            get { return _Sequences; }
+            set => RaiseAndSetIfChanged(ref _Sequences, value);
+        }
+
+        /// <summary>
         /// 绋嬪簭鎵�闇�鍙傛暟
         /// </summary>
         private ObservableCollection<Variable> _Variables;
@@ -30,34 +41,36 @@
         }
 
         /// <summary>
-        /// 搴忓垪闆嗗悎
+        /// 鍒濆鍙傛暟鍙傛暟
         /// </summary>
-        private ObservableCollection<Sequence> _Sequences;
-        public ObservableCollection<Sequence> Sequences
+        private Dictionary<string, Variable> _InitVars;
+        [XmlIgnore]
+        public Dictionary<string, Variable> InitVars
         {
-            get { return _Sequences; }
-            set => RaiseAndSetIfChanged(ref _Sequences, value);
-        }
-
-        /// <summary>
-        /// 鎵�闇�鍙傛暟
-        /// </summary>
-        private Dictionary<string, Variable> _Vars;
-        public Dictionary<string, Variable> Vars
-        {
-            get { return _Vars; }
-            set { _Vars = value; }
+            get { return _InitVars; }
+            set { _InitVars = value; }
         }
 
         /// <summary>
         /// 璁$畻涓存椂鍙傛暟
         /// </summary>
         private Dictionary<string, Variable> _TempVars;
+        [XmlIgnore]
         public Dictionary<string, Variable> TempVars
         {
             get { return _TempVars; }
             set { _TempVars = value; }
         }
 
+        public Program AddSequnce(params Sequence[] sequences)
+        {
+            foreach (Sequence sequence in sequences)
+            {
+                if (sequence == null) continue;
+                sequence.Program = this;
+                Sequences.Add(sequence);
+            }
+            return this;
+        }
     }
 }
diff --git a/Models/Sequence.cs b/Models/Sequence.cs
index 5a3b265..733d122 100644
--- a/Models/Sequence.cs
+++ b/Models/Sequence.cs
@@ -1,9 +1,5 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+锘縰sing System.Collections.ObjectModel;
+using System.Xml.Serialization;
 
 namespace WPFProject.Models
 {
@@ -15,12 +11,14 @@
         {
             get { return _Name; }
             set => RaiseAndSetIfChanged(ref _Name, value);
-        }
+        }
+
+        [XmlIgnore]
+        public Program Program { get; set; }
 
-        private ObservableCollection<Step> _Steps = new ObservableCollection<Step>
-        {
-            new Step{ Name="000"},
-            new Step{ Name="111"}
+        private ObservableCollection<Step> _Steps = new ObservableCollection<Step>() { 
+        
+            new Step{ Name = "000"},new Step{ Name="111"}
         };
         public ObservableCollection<Step> Steps
         {
@@ -28,5 +26,16 @@
             set => RaiseAndSetIfChanged(ref _Steps, value);
         }
 
+        public Sequence AddStep(params Step[] steps)
+        {
+            foreach (Step step in steps)
+            {
+                if (step == null) continue;
+                step.Program = Program;
+                Steps.Add(step);
+            }
+            return this;
+        }
+
     }
 }
diff --git a/Models/Step.cs b/Models/Step.cs
index e532635..ec16fbe 100644
--- a/Models/Step.cs
+++ b/Models/Step.cs
@@ -1,14 +1,12 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+锘縰sing System.Xml.Serialization;
 
 namespace WPFProject.Models
 {
     public class Step : NotifyBase
     {
         #region 瀛楁
+        [XmlIgnore]
+        public Program Program { get; set; }
 
         private int _Index;
         public int Index
diff --git a/Models/Variable.cs b/Models/Variable.cs
index bb63f29..40d05c1 100644
--- a/Models/Variable.cs
+++ b/Models/Variable.cs
@@ -4,55 +4,58 @@
 using System.Security.Policy;
 using System.Text;
 using System.Threading.Tasks;
+using System.Xml.Serialization;
 
 namespace WPFProject.Models
 {
     public class Variable : NotifyBase
     {
-		/// <summary>
-		/// 鍙傛暟鍚�
-		/// </summary>
-		private string _Name;
-		public string Name
-		{
-			get { return _Name; }
-			set => RaiseAndSetIfChanged(ref _Name, value);
-		}
+        /// <summary>
+        /// 鍙傛暟鍚�
+        /// </summary>
+        private string _Name;
+        public string Name
+        {
+            get { return _Name; }
+            set => RaiseAndSetIfChanged(ref _Name, value);
+        }
 
-		/// <summary>
-		/// 鍙傛暟绫诲瀷
-		/// </summary>
-		private string _TypeName;
-		public string TypeName
-		{
-			get { return _TypeName; }
-			set {
-				RaiseAndSetIfChanged(ref _TypeName, value);
-				Type = value == null ? null : Type.GetType(value);
-			}
-		}
+        /// <summary>
+        /// 鍙傛暟绫诲瀷
+        /// </summary>
+        private string _TypeName;
+        public string TypeName
+        {
+            get { return _TypeName; }
+            set
+            {
+                RaiseAndSetIfChanged(ref _TypeName, value);
+                Type = value == null ? null : Type.GetType(value);
+            }
+        }
 
-		public Type Type { get; private set; }
+        [XmlIgnore]
+        public Type Type { get; private set; }
 
-		/// <summary>
-		/// 鍊煎瓧绗�
-		/// </summary>
-		private string _ValueStr;
-		public string ValueStr
-		{
-			get { return _ValueStr; }
-			set => RaiseAndSetIfChanged(ref _ValueStr, value);
-		}
+        /// <summary>
+        /// 鍊煎瓧绗�
+        /// </summary>
+        private string _ValueStr;
+        public string ValueStr
+        {
+            get { return _ValueStr; }
+            set => RaiseAndSetIfChanged(ref _ValueStr, value);
+        }
 
-		/// <summary>
-		/// 鍙傛暟鍊�
-		/// </summary>
-		private object _Value;
-		public object Value
-		{
-			get { return _Value; }
-			set { _Value = value; }
-		}
+        /// <summary>
+        /// 鍙傛暟鍊�
+        /// </summary>
+        private object _Value;
+        public object Value
+        {
+            get { return _Value; }
+            set { _Value = value; }
+        }
 
-	}
+    }
 }
diff --git a/UI/Test/ProgramList.xaml.cs b/UI/Test/ProgramList.xaml.cs
index 79c6d8c..8fb78a2 100644
--- a/UI/Test/ProgramList.xaml.cs
+++ b/UI/Test/ProgramList.xaml.cs
@@ -31,35 +31,21 @@
             }
         }
 
-
         private ObservableCollection<Program> _Programs = new ObservableCollection<Program> {
-
-            new Program{ Name="123",
-            Sequences = new ObservableCollection<Sequence>
-            {
-                new Sequence{ 
+            new Program{ Name="123"}.AddSequnce(new Sequence{
                     Name="S123"
-                },
-                new Sequence
+                },new Sequence
                 {
                     Name="S223"
-                }
-            }
-            },
-            new Program{ Name="223",
-
-             Sequences = new ObservableCollection<Sequence>
-            {
-                new Sequence{
+                }),
+            new Program{ Name="223"}.AddSequnce(new Sequence{
                     Name="D123"
-                },
-                new Sequence
+                },new Sequence
                 {
                     Name="D223"
-                }
-            }
-            }
+                })
         };
+
         public ObservableCollection<Program> Programs
         {
             get { return _Programs; }
diff --git a/UI/WorkControl.xaml.cs b/UI/WorkControl.xaml.cs
index 0e58efc..eecf439 100644
--- a/UI/WorkControl.xaml.cs
+++ b/UI/WorkControl.xaml.cs
@@ -1,231 +1,287 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-using WPFProject.Controls;
-using WPFProject.Models;
-using WPFProject.UI.Test;
-using WPFProject.Utils;
-
-namespace WPFProject.UI
-{
-    /// <summary>
-    /// WorkControl.xaml 鐨勪氦浜掗�昏緫
-    /// </summary>
-    public partial class WorkControl : UserControl,IPlugin
-    {
-        public WorkControl()
-        {
-            InitializeComponent();
-            Loaded += UserControl_Loaded;
-        }
-
-        private List<CanvasPosition> InitGridSize()
-        {
-            List<CanvasPosition> result = new List<CanvasPosition>();
-            result.Add(new CanvasPosition
-            {
-                Left = 0,
-                Top = 0,
-                Width = 0.1 * ActualWidth -2,
-                Height = 0.5 * ActualHeight - 2
-            });
-            result.Add(new CanvasPosition
-            {
-                Left = 0.1*ActualWidth +2,
-                Top = 0,
-                Width = 0.5* ActualWidth -4,
-                Height = ActualHeight,
-            });
-
-            result.Add(new CanvasPosition
-            {
-                Left = 0.6*ActualWidth+2,
-                Top = 0,
-                Width = 0.4*ActualWidth-2,
-                Height = 0.5 * ActualHeight - 2
-            });
-
-            result.Add(new CanvasPosition
-            {
-                Left = 0,
-                Top = 0.5*ActualHeight+2,
-                Width = 0.1 * ActualWidth - 2,
-                Height = 0.5 * ActualHeight - 2
-            });
-
-            result.Add(new CanvasPosition
-            {
-                Left = 0.6 * ActualWidth + 2,
-                Top = 0.5 * ActualHeight + 2,
-                Width = 0.4 * ActualWidth - 2,
-                Height = 0.5 * ActualHeight - 2
-            });
-
-            return result;
-        }
-
-        private void UserControl_Loaded(object sender, RoutedEventArgs e)
-        {
-            List<CanvasPosition> pos = InitGridSize();
-            ProgramList programList = new ProgramList();
-            InnerWindow p = new InnerWindow(pos[0])
-            {
-                Title = "绋嬪簭鍒楄〃",
-                Content = programList
-            };
-            HandleInnerWindow(p);
-
-            InnerWindow p1 = new InnerWindow(pos[1])
-            {
-                Title = "鍥剧墖",
-            };
-            HandleInnerWindow(p1);
-
-            SequnceList sequnceList = new SequnceList();
-            programList.ProgramChanged += sequnceList.Selected_Program_Changed;
-
-            InnerWindow p2 = new InnerWindow(pos[2])
-            {
-                Title = "搴忓垪",
-                Content = sequnceList
-            };
-            HandleInnerWindow(p2);
-
-            FunctionSetting functionSetting = new FunctionSetting();
-            InnerWindow p3 = new InnerWindow(pos[3])
-            {
-                Title = "鍑芥暟",
-                Content = functionSetting
-            };
-            HandleInnerWindow(p3);
-
-            StepSetting stepSetting = new StepSetting();
-            InnerWindow p4 = new InnerWindow(pos[4])
-            {
-                Title = "鍗曟璁剧疆",
-                Content = stepSetting
-            };
-            HandleInnerWindow(p4);
-
-
-            SizeChanged += WorkControl_SizeChanged;
-            Loaded -= UserControl_Loaded;
-
-        }
-
-        public int CanvasChildrenCount { get; private set; } = 0;
-        private void HandleInnerWindow(InnerWindow inner)
-        {
-            inner.MinEvent += InnerWindowMin;
-            inner.MaxEvent += InnerWindowMax;
-            inner.ZIndexEvent += Inner_ZIndexEvent;
-            inner.GotFocus += Inner_GotFocus;
-            inner.AttachToCanvas(WorkArea);
-            inner.Zindex = CanvasChildrenCount++;
+锘縰sing System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using WPFProject.Controls;
+using WPFProject.Models;
+using WPFProject.UI.Test;
+using WPFProject.Utils;
+
+namespace WPFProject.UI
+{
+    /// <summary>
+    /// WorkControl.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
+    public partial class WorkControl : UserControl, IPlugin
+    {
+        public WorkControl()
+        {
+            InitializeComponent();
+            Loaded += UserControl_Loaded;
         }
 
+        private List<CanvasPosition> InitGridSize()
+        {
+            List<CanvasPosition> result = new List<CanvasPosition>();
+            result.Add(new CanvasPosition
+            {
+                Left = 0,
+                Top = 0,
+                Width = 0.1 * ActualWidth - 2,
+                Height = 0.5 * ActualHeight - 2
+            });
+            result.Add(new CanvasPosition
+            {
+                Left = 0.1 * ActualWidth + 2,
+                Top = 0,
+                Width = 0.5 * ActualWidth - 4,
+                Height = ActualHeight,
+            });
+
+            result.Add(new CanvasPosition
+            {
+                Left = 0.6 * ActualWidth + 2,
+                Top = 0,
+                Width = 0.4 * ActualWidth - 2,
+                Height = 0.5 * ActualHeight - 2
+            });
+
+            result.Add(new CanvasPosition
+            {
+                Left = 0,
+                Top = 0.5 * ActualHeight + 2,
+                Width = 0.1 * ActualWidth - 2,
+                Height = 0.5 * ActualHeight - 2
+            });
+
+            result.Add(new CanvasPosition
+            {
+                Left = 0.6 * ActualWidth + 2,
+                Top = 0.5 * ActualHeight + 2,
+                Width = 0.4 * ActualWidth - 2,
+                Height = 0.5 * ActualHeight - 2
+            });
+
+            return result;
+        }
+
+        private void UserControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            List<CanvasPosition> pos = InitGridSize();
+            ProgramList programList = new ProgramList();
+            InnerWindow p = new InnerWindow(pos[0])
+            {
+                Title = "绋嬪簭鍒楄〃",
+                Content = programList
+            };
+            HandleInnerWindow(p);
+
+            InnerWindow p1 = new InnerWindow(pos[1])
+            {
+                Title = "鍥剧墖",
+            };
+            HandleInnerWindow(p1);
+
+            SequnceList sequnceList = new SequnceList();
+            programList.ProgramChanged += sequnceList.Selected_Program_Changed;
+
+            InnerWindow p2 = new InnerWindow(pos[2])
+            {
+                Title = "搴忓垪",
+                Content = sequnceList
+            };
+            HandleInnerWindow(p2);
+
+            FunctionSetting functionSetting = new FunctionSetting();
+            InnerWindow p3 = new InnerWindow(pos[3])
+            {
+                Title = "鍑芥暟",
+                Content = functionSetting
+            };
+            HandleInnerWindow(p3);
+
+            StepSetting stepSetting = new StepSetting();
+            InnerWindow p4 = new InnerWindow(pos[4])
+            {
+                Title = "鍗曟璁剧疆",
+                Content = stepSetting
+            };
+            HandleInnerWindow(p4);
+
+
+            SizeChanged += WorkControl_SizeChanged;
+            Loaded -= UserControl_Loaded;
+
+        }
+
+        public int CanvasChildrenCount { get; private set; } = 0;
+
+        #region InnerWindow鎿嶄綔閫昏緫
+        /// <summary>
+        /// 璁剧疆InnerWindow
+        /// </summary>
+        /// <param name="inner"></param>
+        private void HandleInnerWindow(InnerWindow inner)
+        {
+            inner.MinEvent += InnerWindowMin;
+            inner.MaxEvent += InnerWindowMax;
+            inner.ZIndexEvent += Inner_ZIndexEvent;
+            inner.GotFocus += Inner_GotFocus;
+            inner.AttachToCanvas(WorkArea);
+            inner.Zindex = CanvasChildrenCount++;
+        }
+
+        /// <summary>
+        /// InnerWindow鐒︾偣浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void Inner_GotFocus(object sender, RoutedEventArgs e)
         {
             CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
         }
 
-        private void Inner_ZIndexEvent(object sender, EventArgs e)
-        {
-            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
-        }
-
-        private void HandleMinInnerWindow(InnerWindow inner)
-        {
-            MinInnerWindow min = new MinInnerWindow(inner);
-            min.MaxEvent += MinInnerWindowMax;
-            min.CloseEvent += MinInnerWindowClose;
-            BottomBar.AddMinWindow(min);
-        }
-
-        private void InnerWindowMin(object sender, System.EventArgs e)
-        {
-            InnerWindow inner = sender as InnerWindow;
-            inner.Visibility = Visibility.Collapsed;
-            HandleMinInnerWindow(inner);
-        }
-
-        private void InnerWindowMax(object sender, System.EventArgs e)
-        {
-            InnerWindow inner = sender as InnerWindow;
-            if (inner.WindowState == WindowState.Maximized)
-            {
-                Canvas.SetLeft(inner, inner.canvasPosition.Left);
-                Canvas.SetTop(inner, inner.canvasPosition.Top);
-
-                inner.Width = inner.canvasPosition.Width;
-                inner.Height = inner.canvasPosition.Height;
-                inner.WindowState = WindowState.Normal;
-            }
-            else{
-                Canvas.SetLeft(inner, 0);
-                Canvas.SetTop(inner, 0);
-                inner.Width = WorkArea.ActualWidth;
-                inner.Height = WorkArea.ActualHeight;
-                inner.WindowState = WindowState.Maximized;
-            }
-        }
-
-        private void MinInnerWindowMax(object sender, System.EventArgs e)
-        {
-            MinInnerWindow min = sender as MinInnerWindow;
-            min.Inner.Visibility = Visibility.Visible;
-            CanvasHelper.SetTopZIndex(min.Inner, WorkArea, typeof(InnerWindow));
-            BottomBar.RemoveMinWindow(min);
-        }
-
-        private void MinInnerWindowClose(object sender, System.EventArgs e)
-        {
-            MinInnerWindow min = sender as MinInnerWindow;
-            BottomBar.RemoveMinWindow(min);
-        }
-
-
-        private void WorkControl_SizeChanged(object sender, SizeChangedEventArgs e)
-        {
-            Size newSize = e.NewSize;
-            Size previousSize = e.PreviousSize;
-
-            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
-            {
-                UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
-                if (Canvas.GetLeft(child) >= newSize.Width)
-                {
-                    Canvas.SetLeft(child, Canvas.GetLeft(child) + newSize.Width - previousSize.Width);
-                }
-                if (Canvas.GetTop(child) >= newSize.Height)
-                {
-                    Canvas.SetTop(child, Canvas.GetTop(child) + newSize.Height - previousSize.Height);
-                }
-            }
-        }
-
-
-        public void OnTabChange(object sender, SelectionChangedEventArgs args)
-        {
-            if (args.AddedItems.Count > 0)
-            {
-                IconTabItem newTab = args.AddedItems[0] as IconTabItem;
-                if (newTab != null && newTab.Content == this)
-                { 
-                    
-                }
-            }
-
-            if (args.RemovedItems.Count > 0)
-            {
-                IconTabItem oldTab = args.RemovedItems[0] as IconTabItem;
-                if (oldTab != null && oldTab.Content == this)
-                {
-
-                }
-            }
-        }
-    }
-}
+        /// <summary>
+        /// InnerWindow ZIndex鍒囨崲浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void Inner_ZIndexEvent(object sender, EventArgs e)
+        {
+            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
+        }
+
+        /// <summary>
+        /// InnerWindow鏈�灏忓寲浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void InnerWindowMin(object sender, System.EventArgs e)
+        {
+            InnerWindow inner = sender as InnerWindow;
+            inner.Visibility = Visibility.Collapsed;
+            HandleMinInnerWindow(inner);
+        }
+
+        /// <summary>
+        /// InnerWindow鏈�澶у寲浜嬩欢
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void InnerWindowMax(object sender, System.EventArgs e)
+        {
+            InnerWindow inner = sender as InnerWindow;
+            if (inner.WindowState == WindowState.Maximized)
+            {
+                Canvas.SetLeft(inner, inner.canvasPosition.Left);
+                Canvas.SetTop(inner, inner.canvasPosition.Top);
+
+                inner.Width = inner.canvasPosition.Width;
+                inner.Height = inner.canvasPosition.Height;
+                inner.WindowState = WindowState.Normal;
+            }
+            else
+            {
+                Canvas.SetLeft(inner, 0);
+                Canvas.SetTop(inner, 0);
+                inner.Width = WorkArea.ActualWidth;
+                inner.Height = WorkArea.ActualHeight;
+                inner.WindowState = WindowState.Maximized;
+            }
+        }
+
+        /// <summary>
+        /// 閲嶈澶у皬
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void WorkControl_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            //Size newSize = e.NewSize;
+            //Size previousSize = e.PreviousSize;
+
+            //double xRate = newSize.Width / previousSize.Width;
+            //double yRate = newSize.Height / previousSize.Height;
+            //for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
+            //{
+            //    UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
+            //    Canvas.SetLeft(child, Canvas.GetLeft(child) * xRate);
+            //    Canvas.SetTop(child, Canvas.GetTop(child) * yRate);
+            //}
+
+            //for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
+            //{
+            //    UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
+            //    if (Canvas.GetLeft(child) >= newSize.Width)
+            //    {
+            //        Canvas.SetLeft(child, Canvas.GetLeft(child) + newSize.Width - previousSize.Width);
+            //    }
+            //    if (Canvas.GetTop(child) >= newSize.Height)
+            //    {
+            //        Canvas.SetTop(child, Canvas.GetTop(child) + newSize.Height - previousSize.Height);
+            //    }
+            //}
+        }
+        #endregion
+
+        #region 搴曢儴MinInnerWindow鐩稿叧
+        /// <summary>
+        /// 搴曢儴MinInnerWindow澶勭悊
+        /// </summary>
+        /// <param name="inner"></param>
+        private void HandleMinInnerWindow(InnerWindow inner)
+        {
+            MinInnerWindow min = new MinInnerWindow(inner);
+            min.MaxEvent += MinInnerWindowMax;
+            min.CloseEvent += MinInnerWindowClose;
+            BottomBar.AddMinWindow(min);
+        }
+
+        /// <summary>
+        /// 搴曢儴MinInnerWindow灞曞紑
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void MinInnerWindowMax(object sender, System.EventArgs e)
+        {
+            MinInnerWindow min = sender as MinInnerWindow;
+            min.Inner.Visibility = Visibility.Visible;
+            CanvasHelper.SetTopZIndex(min.Inner, WorkArea, typeof(InnerWindow));
+            BottomBar.RemoveMinWindow(min);
+        }
+
+        /// <summary>
+        /// 搴曢儴MinInnerWin鍏抽棴
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void MinInnerWindowClose(object sender, System.EventArgs e)
+        {
+            MinInnerWindow min = sender as MinInnerWindow;
+            BottomBar.RemoveMinWindow(min);
+        }
+        #endregion
+
+        public void OnTabChange(object sender, SelectionChangedEventArgs args)
+        {
+            if (args.AddedItems.Count > 0)
+            {
+                IconTabItem newTab = args.AddedItems[0] as IconTabItem;
+                if (newTab != null && newTab.Content == this)
+                {
+
+                }
+            }
+
+            if (args.RemovedItems.Count > 0)
+            {
+                IconTabItem oldTab = args.RemovedItems[0] as IconTabItem;
+                if (oldTab != null && oldTab.Content == this)
+                {
+
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/Utils/Resize.cs b/Utils/Resize.cs
index 63c9c73..bbc5615 100644
--- a/Utils/Resize.cs
+++ b/Utils/Resize.cs
@@ -346,6 +346,8 @@
                 if (_resizeType == ResizeType.Canvas && _resizeTarget is InnerWindow _inner)
                 {
                     Canvas parent = GetCanvas(_inner);
+                    // 濡傛灉鏄釜InnerWindow锛屽氨鎶奍nnerWindowZIndex缃《
+                    // TODO 鍙互鏀规垚鎺ュ彛鎴栬�匘ependencyPrope鏉ュ仛
                     CanvasHelper.SetTopZIndex(_inner, parent, _inner.GetType());
                 }
             }
@@ -415,42 +417,80 @@
                                 return;
                             }
 
+                            double oldLeft = double.IsNaN(Canvas.GetLeft(target)) ? 0 : Canvas.GetLeft(target),
+                                oldTop = double.IsNaN(Canvas.GetTop(target)) ? 0 : Canvas.GetTop(target),
+                                oldWidth = double.IsNaN(target.ActualWidth) ? 0 : target.ActualWidth,
+                                oldHeight = double.IsNaN(target.ActualHeight) ? 0 : target.ActualHeight;
+
                             double left, top, width, height;
-                            if (thumb.HorizontalAlignment == HorizontalAlignment.Left)
+                            double x = e.HorizontalChange, y = e.VerticalChange;
+                            bool toLeft = x < 0, toTop = y < 0;
+                            bool isLeft = thumb.HorizontalAlignment == HorizontalAlignment.Left,
+                                isTop = thumb.VerticalAlignment == VerticalAlignment.Top;
+                            if (isLeft)
                             {
-                                left = double.IsNaN(Canvas.GetLeft(target)) ? 0 : Canvas.GetLeft(target) + e.HorizontalChange;
-                                width = (double.IsNaN(target.ActualWidth) ? 0 : target.ActualWidth) - e.HorizontalChange;
+                                // 宸︿晶鐨勬嫋鎷�
+                                left = oldLeft + x;
+                                width = oldWidth - x;
+                                if (left < 0) { left = 0; width = oldWidth - (left - oldLeft); }
+                                width = width < MinWidth ? MinWidth : width;
                             }
                             else
                             {
-                                left = Canvas.GetLeft(target);
-                                width = (double.IsNaN(target.ActualWidth) ? 0 : target.ActualWidth) + e.HorizontalChange;
+                                // 鍙充晶鐨勬嫋鎷�
+                                left = oldLeft >= 0 ? oldLeft : 0;
+                                width = oldWidth + x;
+                                width = width < MinWidth ? MinWidth : width;
+                                if (left + width > parent.ActualWidth) width = parent.ActualWidth - left;
                             }
-                            if (thumb.VerticalAlignment == VerticalAlignment.Top)
+
+                            if (isTop)
                             {
-                                top = double.IsNaN(Canvas.GetTop(target)) ? 0 : Canvas.GetTop(target) + e.VerticalChange;
-                                height = (double.IsNaN(target.ActualHeight) ? 0 : target.ActualHeight) - e.VerticalChange;
+                                // 涓婅竟鐨勬嫋鎷�
+                                top = oldTop + y;
+                                height = oldHeight - y;
+                                if (top < 0) { top = 0; height = oldHeight - (top - oldTop); }
+                                height = height < MinHeight ? MinHeight : height;
                             }
                             else
                             {
-                                top = Canvas.GetTop(target);
-                                height = (double.IsNaN(target.ActualHeight) ? 0 : target.ActualHeight) + e.VerticalChange;
+                                // 涓嬭竟鐨勬嫋鎷�
+                                top = oldTop > 0 ? oldTop : 0;
+                                height = oldHeight + y;
+                                height = height < MinHeight ? MinHeight : height;
+                                if (top + height > parent.ActualHeight) height = parent.ActualHeight - top;
                             }
-                            if (thumb.HorizontalAlignment != HorizontalAlignment.Center && thumb.HorizontalAlignment != HorizontalAlignment.Stretch)
+
+                            if (thumb.HorizontalAlignment != HorizontalAlignment.Center &&
+                                thumb.HorizontalAlignment != HorizontalAlignment.Stretch)
                             {
-                                if (e.HorizontalChange > 0 || (width >= MinWidth && left >= 0))
-                                {
-                                    Canvas.SetLeft(target, left);
-                                    target.Width = width;
-                                }
+                                // 姘村钩鏂瑰悜鏈�缁堝垽鏂�
+                                Canvas.SetLeft(target, left);
+                                target.Width = width;
+                                //if ((isLeft && toLeft && left >= 0) ||
+                                //    (isLeft && !toLeft && width >= MinWidth) ||
+                                //    (!isLeft && toLeft && width >= MinWidth) ||
+                                //    (!isLeft && !toLeft && (left + width) <= parent.ActualWidth))
+                                //{
+                                //    Canvas.SetLeft(target, left);
+                                //    target.Width = width;
+                                //}
                             }
-                            if (thumb.VerticalAlignment != VerticalAlignment.Center && thumb.VerticalAlignment != VerticalAlignment.Stretch)
+
+                            if (thumb.VerticalAlignment != VerticalAlignment.Center &&
+                                thumb.VerticalAlignment != VerticalAlignment.Stretch)
                             {
-                                if (e.VerticalChange > 0 || (height >= MinHeight && top >= 0))
-                                {
-                                    Canvas.SetTop(target, top);
-                                    target.Height = height;
-                                }
+                                // 鍨傜洿鏂瑰悜鏈�缁堝垽鏂�
+                                Canvas.SetTop(target, top);
+                                target.Height = height;
+                                //if ((isTop && toTop && top >= 0) ||
+                                //    (isTop && !toTop && height >= MinHeight) ||
+                                //    (!isTop && toTop && height >= MinHeight) ||
+                                //    (!isTop && !toTop && (top + height) <= parent.ActualHeight))
+                                //{
+                                //    Canvas.SetTop(target, top);
+                                //    target.Height = height;
+                                //}
                             }
                         }
                         break;
diff --git a/test.xml b/test.xml
index 353bc2a..2788da7 100644
--- a/test.xml
+++ b/test.xml
@@ -7,9 +7,11 @@
         <Name>S123</Name>
         <Steps>
           <Step>
+            <Index>0</Index>
             <Name>000</Name>
           </Step>
           <Step>
+            <Index>0</Index>
             <Name>111</Name>
           </Step>
         </Steps>
@@ -18,9 +20,11 @@
         <Name>S223</Name>
         <Steps>
           <Step>
+            <Index>0</Index>
             <Name>000</Name>
           </Step>
           <Step>
+            <Index>0</Index>
             <Name>111</Name>
           </Step>
         </Steps>
@@ -34,9 +38,11 @@
         <Name>D123</Name>
         <Steps>
           <Step>
+            <Index>0</Index>
             <Name>000</Name>
           </Step>
           <Step>
+            <Index>0</Index>
             <Name>111</Name>
           </Step>
         </Steps>
@@ -45,9 +51,11 @@
         <Name>D223</Name>
         <Steps>
           <Step>
+            <Index>0</Index>
             <Name>000</Name>
           </Step>
           <Step>
+            <Index>0</Index>
             <Name>111</Name>
           </Step>
         </Steps>

--
Gitblit v1.9.1