| File was renamed from UI/WorkControl.xaml.cs |
| | |
| | | using 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));
|
| | | }
|
| | |
|
| | | /// <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)
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | using 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)); |
| | | } |
| | | |
| | | /// <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) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |