asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
namespace RichCreator.Editor.Tools.CV
{
    /// <summary>
    /// DialogReplica.xaml 的交互逻辑
    /// </summary>
    public partial class SplitArea : UserControl
    {
        private Cursor _cursor;
 
        public SplitArea()
        {
            InitializeComponent();
        }
 
        private void OnResizeThumbDragStarted(object sender, DragStartedEventArgs e)
        {
            _cursor = Cursor;
            Cursor = Cursors.SizeNWSE;
        }
 
        private void OnResizeThumbDragCompleted(object sender, DragCompletedEventArgs e)
        {
            Cursor = _cursor;
        }
 
        private void OnResizeThumbDragDelta(object sender, DragDeltaEventArgs e)
        {
            double width = double.IsNaN(sizableContent.Width)?0:sizableContent.Width;
            double height =double.IsNaN(sizableContent.Height)?0:sizableContent.Height;
 
            double xAdjust = width + e.HorizontalChange;
            double yAdjust = height + e.VerticalChange;
 
            //make sure not to resize to negative width or heigth            
            xAdjust = xAdjust < sizableContent.MinWidth ? sizableContent.MinWidth: xAdjust ;
            yAdjust =  yAdjust < sizableContent.MinHeight ? sizableContent.MinHeight:yAdjust ;
 
            sizableContent.Width = xAdjust;
            sizableContent.Height = yAdjust;
        }
 
        private void Thumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            _cursor = Cursor;
            Cursor = Cursors.Arrow;
        }
 
        private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            Cursor = _cursor;
        }
 
        private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            double left = Canvas.GetLeft(this);
            double top = Canvas.GetTop(this);
 
            double xAdjust =(double.IsNaN(left)?0:left) + e.HorizontalChange;
            double yAdjust = (double.IsNaN(top)?0:top)+ e.VerticalChange;
            
            
 
            Canvas.SetLeft(this, xAdjust);
            Canvas.SetTop(this, yAdjust);
        }
 
        /// <summary>
        /// 得到控件的Rect
        /// </summary>
        /// <returns></returns>
        public Rect GetRect()
        {
            return new Rect(Canvas.GetLeft(this), Canvas.GetTop(this), this.ActualWidth, this.ActualHeight);
        }
 
        public event Action<SplitArea> OnClose;
        private void raiseOnClose()
        {
            if (OnClose != null)
            {
                OnClose(this);
            }
        }
 
 
        /// <summary>
        /// 关闭点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            raiseOnClose();
        }
    }
}