From 25dd2203bb3b995d73c43733b3aaa049ec28b4a9 Mon Sep 17 00:00:00 2001
From: chr <chrry550@163.com>
Date: 星期二, 12 三月 2024 09:42:43 +0800
Subject: [PATCH] 初版Step运行代码;

---
 Utils/Resize.cs |  163 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 125 insertions(+), 38 deletions(-)

diff --git a/Utils/Resize.cs b/Utils/Resize.cs
index 10591b5..bbc5615 100644
--- a/Utils/Resize.cs
+++ b/Utils/Resize.cs
@@ -6,6 +6,8 @@
 using System.Windows.Media;
 using System;
 using System.Windows.Shapes;
+using WPFProject.Controls;
+using System.Xml.Linq;
 
 namespace WPFProject.Utils
 {
@@ -107,6 +109,18 @@
         static readonly DependencyProperty ResizeableProperty =
            DependencyProperty.RegisterAttached("Resizeable", typeof(Resizeable), typeof(Resize), new PropertyMetadata(null));
 
+        static int i = 0;
+        static SolidColorBrush[] colors = new SolidColorBrush[] {
+            new SolidColorBrush(Colors.White),
+            new SolidColorBrush(Colors.Red),
+            new SolidColorBrush(Colors.Blue),
+            new SolidColorBrush(Colors.Green),
+            new SolidColorBrush(Colors.LightBlue),
+            new SolidColorBrush(Colors.Orange),
+            new SolidColorBrush(Colors.Yellow),
+            new SolidColorBrush(Colors.Black),
+        };
+
         public class Resizeable
         {
             ResizeType _resizeType;
@@ -140,22 +154,32 @@
                     _thumbsParent = VisualTreeHelper.GetChild(thumbsRoot, 0) as FrameworkElement;
                 }
 
-
                 if (thumbsRoot != null)
                 {
-                    UIElement target = _resizeTarget is Window _windowTarget ? _windowTarget.Content as UIElement : _resizeTarget;
-                    if (target != null)
+                    UIElement element = _resizeTarget is Window _windowTarget ? _windowTarget.Content as UIElement : _resizeTarget;
+                    if (element != null)
                     {
-                        AdornerLayer layer = AdornerLayer.GetAdornerLayer(target);
-                        if (layer == null) throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
-                        layer.Add(new ResizeAdorner(target, thumbsRoot));
+                        if (element is InnerWindow _inner)
+                        {
+                            AdornerLayer layer = _inner.ResizeAdornerDecorator.AdornerLayer;
+                            if (layer == null)
+                                throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
+                            layer.Add(new ResizeAdorner(layer, thumbsRoot));
+                        }
+                        else
+                        {
+                            AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
+                            if (layer == null)
+                                throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
+                            layer.Add(new ResizeAdorner(element, thumbsRoot));
+                        }
                     }
                 }
 
                 // 浣跨敤缂虹渷鏍峰紡
                 if (thumbsRoot == null)
                 {
-                    Thumb leftThumb = null, topThumb = null, rightThumb = null, bottomThumb = null, 
+                    Thumb leftThumb = null, topThumb = null, rightThumb = null, bottomThumb = null,
                         lefTopThumb = null, rightTopThumb = null, rightBottomThumb = null, leftbottomThumb = null;
                     int thumnSize = 5;
                     // 鍒濆鍖杢humb
@@ -251,6 +275,7 @@
                     leftbottomThumb.Width = thumnSize;
                     leftbottomThumb.Height = thumnSize;
 
+
                     Grid grid = new Grid();
                     grid.Children.Add(leftThumb);
                     grid.Children.Add(topThumb);
@@ -271,10 +296,20 @@
                     }
                     if (element != null)
                     {
-                        var layer = AdornerLayer.GetAdornerLayer(element);
-                        if (layer == null)
-                            throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
-                        layer.Add(new ResizeAdorner(element, grid));
+                        if (element is InnerWindow _inner)
+                        {
+                            AdornerLayer layer = _inner.ResizeAdornerDecorator.AdornerLayer;
+                            if (layer == null)
+                                throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
+                            layer.Add(new ResizeAdorner(layer, grid));
+                        }
+                        else
+                        {
+                            AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);
+                            if (layer == null)
+                                throw new Exception("鑾峰彇鎺т欢瑁呴グ灞傚け璐ワ紝鎺т欢鍙兘娌℃湁瑁呴グ灞傦紒");
+                            layer.Add(new ResizeAdorner(element, grid));
+                        }
                     }
                     thumbsRoot = grid;
                     _thumbsParent = thumbsRoot;
@@ -308,12 +343,15 @@
             private void Thumb_DragStarted(object sender, DragStartedEventArgs e)
             {
                 _resizeType = GetResizeType();
-                if (_resizeType == ResizeType.Canvas)
+                if (_resizeType == ResizeType.Canvas && _resizeTarget is InnerWindow _inner)
                 {
-                    Canvas parent = GetCanvas(_resizeTarget);
-                    CanvasHelper.SetTopZIndex(_resizeTarget, parent, _resizeTarget.GetType());
+                    Canvas parent = GetCanvas(_inner);
+                    // 濡傛灉鏄釜InnerWindow锛屽氨鎶奍nnerWindowZIndex缃《
+                    // TODO 鍙互鏀规垚鎺ュ彛鎴栬�匘ependencyPrope鏉ュ仛
+                    CanvasHelper.SetTopZIndex(_inner, parent, _inner.GetType());
                 }
             }
+
             private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
             {
                 switch (_resizeType)
@@ -369,7 +407,7 @@
                         }
                         break;
                     case ResizeType.Canvas:
-                        {   
+                        {
                             FrameworkElement target = _resizeTarget;
                             Canvas parent = GetCanvas(target);
                             FrameworkElement thumb = sender as FrameworkElement;
@@ -379,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;
@@ -501,7 +577,7 @@
             }
 
             // 瑁呴グ鍣�
-            class ResizeAdorner : Adorner
+            public class ResizeAdorner : Adorner
             {
                 // 甯冨眬瀹瑰櫒锛屽鏋滀笉浣跨敤甯冨眬瀹瑰櫒锛屽垯闇�瑕佺粰涓婅堪8涓帶浠跺竷灞�锛屽疄鐜板拰Grid甯冨眬瀹氫綅鏄竴鏍风殑锛屼細姣旇緝绻佺悙涓旀剰涔変笉澶с��
                 UIElement _child;
@@ -522,6 +598,17 @@
                     _child.Arrange(new Rect(new Point(0, 0), finalSize));
                     return finalSize;
                 }
+                public void ttt(int index)
+                {
+                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(_child); i++)
+                    {
+                        DependencyObject child = VisualTreeHelper.GetChild(_child, i);
+                        Canvas.SetZIndex(child as UIElement, index);
+
+                    }
+
+                }
+
             }
         }
 

--
Gitblit v1.9.1