|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 |
- using BeDesignerSCADA.Common;
- using BPASmartClient.Compiler;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Markup;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
-
- namespace BeDesignerSCADA.Controls
- {
- /// <summary>
- /// MenuRunCanvas.xaml 的交互逻辑
- /// </summary>
- public partial class MenuRunCanvas : UserControl
- {
- MenuRunCanvasModel menuRunCanvasModel = null;
- ResourceDictionary languageResDic = new ResourceDictionary();
- DispatcherTimer timer1;//控制菜单显示隐藏功能
- public MenuRunCanvas()
- {
- InitializeComponent();
-
- languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
- menuRunCanvasModel =new MenuRunCanvasModel();
- this.DataContext=menuRunCanvasModel;
- timer1 = new DispatcherTimer();
- timer1.Tick += new System.EventHandler(timer1_Tick);
- timer1.Interval = new TimeSpan(0, 0, 0, 0, 1000);
- timer1.Start();
- this.Loaded += MenuRunCanvas_Loaded;
- }
-
- private void MenuRunCanvas_Loaded(object sender, RoutedEventArgs e)
- {
- if (menuRunCanvasModel.MenuModel != null)
- {
- switch (menuRunCanvasModel.MenuModel.Alignment)
- {
- case MenuAlignment.左边:
- menuWidth = wrapanl_main.ActualWidth;
- break;
- case MenuAlignment.顶部:
- menuWidth = wrapanl_main.ActualHeight;
- break;
- case MenuAlignment.右边:
- menuWidth = wrapanl_main.ActualWidth;
- break;
- case MenuAlignment.底部:
- menuWidth = wrapanl_main.ActualHeight;
- break;
- default:
- break;
- }
- MenuSmall();
- }
- }
-
- private void timer1_Tick(object sender, EventArgs e)
- {
- times += 1;
- }
-
- /// <summary>
- /// 根据路径运行程序
- /// </summary>
- public void LoadingData(string path)
- {
- RunMenu(BinaryFile.ReadBinary<MenuModel>(path) as MenuModel);
- }
- /// <summary>
- /// 运行菜单
- /// </summary>
- /// <param name="canvas"></param>
- public void RunMenu(MenuModel canvas)
- {
- int k = 0;
- ItemsPanelTemplate itemsPanelTemplate = new ItemsPanelTemplate();
- FrameworkElementFactory _StackPanel = new FrameworkElementFactory(typeof(StackPanel));
- switch (canvas.Alignment)
- {
- case MenuAlignment.左边:
- if(!string.IsNullOrEmpty(canvas.Name))
- k = (canvas.Name.Length / 5 -1+ (canvas.Name.Length % 5 > 0 ? 1 : 0))*15;
- //左边菜单栏
- PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
- PageList.VerticalAlignment = VerticalAlignment.Top;
- PageList.Margin = new Thickness(10,70+ k, 10,110);
- PageList.Padding = new Thickness(0,0,0,0);
- _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
- //标题栏
- TitleName.Margin = new Thickness(0, 10, 0, 10);
- TitleName.HorizontalAlignment = HorizontalAlignment.Stretch;
- TitleName.VerticalAlignment = VerticalAlignment.Top;
- border0.Margin = new Thickness(0, 60+k, 0, 0);
- border0.LayoutTransform = new RotateTransform() { Angle = 0 };
- border0.HorizontalAlignment = HorizontalAlignment.Stretch;
- border0.VerticalAlignment = VerticalAlignment.Top;
- border1.Margin = new Thickness(0, 0, 0, 100);
- border1.LayoutTransform = new RotateTransform() { Angle = 0 };
- border1.HorizontalAlignment = HorizontalAlignment.Stretch;
- border1.VerticalAlignment = VerticalAlignment.Bottom;
- //内部Grid
- wrapanl_main.HorizontalAlignment = HorizontalAlignment.Left;
- wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch;
- wrapanl_main.Margin = new Thickness(0, 0, 0, 25);
- //外部Stackpanl
- waibustack.Orientation = Orientation.Horizontal;
- waibustack.HorizontalAlignment = HorizontalAlignment.Left;
- //拉出按钮
- lachu.HorizontalAlignment = HorizontalAlignment.Left;
- lachu.VerticalAlignment = VerticalAlignment.Stretch;
- lachu.BorderThickness = new Thickness(1, 0, 0, 0);
- //closeGrid
- closeGrid.HorizontalAlignment = HorizontalAlignment.Center;
- closeGrid.VerticalAlignment = VerticalAlignment.Bottom;
- closeGrid.Margin = new Thickness(10);
- ButClose.Margin = new Thickness(0, 5, 0, 0);
- break;
- case MenuAlignment.顶部:
- //左边菜单栏
- PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
- PageList.VerticalAlignment = VerticalAlignment.Top;
- PageList.Margin = new Thickness(140,0 , 120, 0);
- PageList.Padding = new Thickness(0, 0, 0, 0);
- _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
- //标题栏
- TitleName.LayoutTransform = new RotateTransform() { Angle = 0 };
- TitleName.Margin = new Thickness(10, 10, 10, 10);
- TitleName.HorizontalAlignment = HorizontalAlignment.Left;
- TitleName.VerticalAlignment = VerticalAlignment.Center;
- TitleName.Width = 110;
- border0.Margin = new Thickness(130, 0, 0, 0);
- border0.HorizontalAlignment = HorizontalAlignment.Left;
- border0.VerticalAlignment = VerticalAlignment.Stretch;
- border0.LayoutTransform = new RotateTransform() { Angle = 90 };
- border1.Margin = new Thickness(0, 0, 110,0 );
- border1.HorizontalAlignment = HorizontalAlignment.Right;
- border1.VerticalAlignment = VerticalAlignment.Stretch;
- border1.LayoutTransform = new RotateTransform() { Angle = 90 };
- //内部Grid
- wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch;
- wrapanl_main.VerticalAlignment = VerticalAlignment.Top;
- wrapanl_main.Margin = new Thickness(0, 0, 0, 0);
- //外部Stackpanl
- waibustack.Orientation = Orientation.Vertical;
- waibustack.VerticalAlignment = VerticalAlignment.Top;
- //拉出按钮
- lachu.HorizontalAlignment = HorizontalAlignment.Stretch;
- lachu.VerticalAlignment = VerticalAlignment.Top;
- lachu.LayoutTransform = new RotateTransform() { Angle = 270 };
- lachu.BorderThickness = new Thickness(0, 0, 1, 0);
- //closeGrid
- closeGrid.HorizontalAlignment = HorizontalAlignment.Right;
- closeGrid.VerticalAlignment = VerticalAlignment.Center;
- closeGrid.Margin = new Thickness(10, 0, 10, 0);
- ButClose.Margin = new Thickness(0,5, 0, 0);
- break;
- case MenuAlignment.右边:
- k = (canvas.Name.Length / 5 - 1 + (canvas.Name.Length % 5 > 0 ? 1 : 0)) * 15;
- //左边菜单栏
- PageList.HorizontalAlignment = HorizontalAlignment.Right;
- PageList.VerticalAlignment = VerticalAlignment.Stretch;
- PageList.Margin = new Thickness(10, 70 + k, 10, 110);
- PageList.Padding = new Thickness(0, 0, 0, 0);
- _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
- //标题栏
- TitleName.Margin = new Thickness(0, 10, 0, 10);
- TitleName.HorizontalAlignment = HorizontalAlignment.Stretch;
- TitleName.VerticalAlignment = VerticalAlignment.Top;
- border0.Margin = new Thickness(0, 60 + k, 0, 0);
- border0.LayoutTransform = new RotateTransform() { Angle = 0 };
- border0.HorizontalAlignment = HorizontalAlignment.Stretch;
- border0.VerticalAlignment = VerticalAlignment.Top;
- border1.Margin = new Thickness(0, 0, 0, 100);
- border1.LayoutTransform = new RotateTransform() { Angle = 0 };
- border1.HorizontalAlignment = HorizontalAlignment.Stretch;
- border1.VerticalAlignment = VerticalAlignment.Bottom;
- //内部Grid
- wrapanl_main.HorizontalAlignment = HorizontalAlignment.Right;
- wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch;
- wrapanl_main.Margin = new Thickness(0, 0, 0, 25);
- //外部Stackpanl
- waibustack.Orientation = Orientation.Horizontal;
- waibustack.HorizontalAlignment = HorizontalAlignment.Right;
- //拉出按钮
- lachu.HorizontalAlignment = HorizontalAlignment.Right;
- lachu.VerticalAlignment = VerticalAlignment.Stretch;
- lachu.BorderThickness = new Thickness(0, 0, 1, 0);
- //closeGrid
- closeGrid.HorizontalAlignment = HorizontalAlignment.Center;
- closeGrid.VerticalAlignment = VerticalAlignment.Bottom;
- closeGrid.Margin = new Thickness(10);
- ButClose.Margin = new Thickness(0, 5, 0, 0);
- FrameworkElement border = null;
- foreach (FrameworkElement item in waibustack.Children)
- {
- if (item is Border)
- border = item;
- }
- waibustack.Children.Remove(border);
- waibustack.Children.Insert(0,border);
-
- break;
- case MenuAlignment.底部:
- //左边菜单栏
- PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
- PageList.VerticalAlignment = VerticalAlignment.Bottom;
- PageList.Margin = new Thickness(140, 0, 120, 0);
- PageList.Padding = new Thickness(0, 0, 0, 0);
- _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
- //标题栏
- TitleName.LayoutTransform = new RotateTransform() { Angle = 0 };
- TitleName.Margin = new Thickness(10, 10, 10, 10);
- TitleName.HorizontalAlignment = HorizontalAlignment.Left;
- TitleName.VerticalAlignment = VerticalAlignment.Center;
- TitleName.Width = 110;
- border0.Margin = new Thickness(130, 0, 0, 0);
- border0.HorizontalAlignment = HorizontalAlignment.Left;
- border0.VerticalAlignment = VerticalAlignment.Stretch;
- border0.LayoutTransform = new RotateTransform() { Angle = 90 };
- border1.Margin = new Thickness(0, 0, 110, 0);
- border1.HorizontalAlignment = HorizontalAlignment.Right;
- border1.VerticalAlignment = VerticalAlignment.Stretch;
- border1.LayoutTransform = new RotateTransform() { Angle = 90 };
- //内部Grid
- wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch;
- wrapanl_main.VerticalAlignment = VerticalAlignment.Bottom;
- wrapanl_main.Margin = new Thickness(0, 0, 0, 0);
- //外部Stackpanl
- waibustack.Orientation = Orientation.Vertical;
- waibustack.VerticalAlignment = VerticalAlignment.Bottom;
- waibustack.Margin = new Thickness(0, 0, 0, 25);
- //拉出按钮
- lachu.HorizontalAlignment = HorizontalAlignment.Stretch;
- lachu.VerticalAlignment = VerticalAlignment.Bottom;
- lachu.LayoutTransform = new RotateTransform() { Angle = 270 };
- lachu.BorderThickness = new Thickness(1, 0, 0, 0);
- lachu.Margin = new Thickness(0, 0, 0, 0);
- //closeGrid
- closeGrid.HorizontalAlignment = HorizontalAlignment.Right;
- closeGrid.VerticalAlignment = VerticalAlignment.Center;
- closeGrid.Margin = new Thickness(10, 0, 10, 0);
- ButClose.Margin = new Thickness(0, 5, 0, 0);
- border = null;
- foreach (FrameworkElement item in waibustack.Children)
- {
- if (item is Border)
- border = item;
- }
- waibustack.Children.Remove(border);
- waibustack.Children.Insert(0, border);
- break;
- default:
- break;
- }
- if(canvas.IsVisibility)
- waibustack.Visibility = Visibility.Visible;
- else
- waibustack.Visibility = Visibility.Collapsed;
- itemsPanelTemplate.VisualTree = _StackPanel;
- PageList.ItemsPanel = itemsPanelTemplate;
- menuRunCanvasModel.MenuModel = canvas;
- menuRunCanvasModel.border = main;
- menuRunCanvasModel.MenuModel?.pageModels?.ToList().ForEach(par =>
- {
- List<FrameworkElement> Children = new List<FrameworkElement>();
- par.visual = new CanvasPanel();
- par?.ChildrenStr?.ForEach(k =>
- {
- FrameworkElement item = XamlReader.Parse(k) as FrameworkElement;
- par.visual.Children.Add(item);
- FrameworkElement item1 = XamlReader.Parse(k) as FrameworkElement;
- Children.Add(item1);
- });
- RunCanvas runCanvas = new RunCanvas();
- runCanvas.Init(Children);
- par.runCanvas = runCanvas;
- });
- if (menuRunCanvasModel.MenuModel.pageModels.Count > 0)
- {
- menuRunCanvasModel.MenuModel.SelectPageModels = menuRunCanvasModel.MenuModel.pageModels[0];
- main.Child = menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas;
- menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas.RunSelect();
- }
- }
- /// <summary>
- /// 父窗体控制事件
- /// </summary>
- /// <param name="obj"></param>
- public void PandClick(Window obj)
- {
- this.ButClose.Click += (o, e) =>
- {
- MessageBoxResult res = MessageBox.Show("确定关闭上位机软件?", "警告", MessageBoxButton.OKCancel);
- if (res == MessageBoxResult.OK)
- {
- obj.Close();
- }
-
- };
- this.waibustack.MouseLeftButtonDown += (o, e) =>
- {
- if (e.ClickCount > 1)
- {
- if (obj.WindowState == WindowState.Maximized)
- obj.WindowState = WindowState.Normal;
- else if (obj.WindowState == WindowState.Normal)
- obj.WindowState = WindowState.Maximized;
- }
- if (e.LeftButton == MouseButtonState.Pressed) obj.DragMove();
- };
- }
-
- bool ismove = true;
- int times = 0;
- /// <summary>
- /// 鼠标移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void wrapanl_main_MouseMove(object sender, MouseEventArgs e)
- {
- if (times < 1)
- {
- return;
- }
- if (ismove)
- {
- ismove = false;
- MenuBig();
-
- }
- times = 0;
- }
- /// <summary>
- /// 鼠标离开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void wrapanl_main_MouseLeave(object sender, MouseEventArgs e)
- {
- menuWidthDefault = 0;
- if (!ismove)
- {
- ismove = true;
- MenuSmall();
- }
- times = 0;
- }
-
-
- private int menuWidthDefault = 0;
- private double menuWidth = 86;
- private void MenuBig()
- {
-
- DoubleAnimation da = new DoubleAnimation();
- da.From = menuWidthDefault;
- da.To = menuWidth;
- da.Duration = TimeSpan.FromSeconds(0.1);
- if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
- {
- wrapanl_main.BeginAnimation(WidthProperty, da);
- if (languageResDic.Contains("image左1"))
- lachuStyle.Style = languageResDic["image左1"] as Style;
- }
- else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
- {
- wrapanl_main.BeginAnimation(HeightProperty, da);
- if (languageResDic.Contains("image右1"))
- lachuStyle.Style = languageResDic["image右1"] as Style;
- }
- }
- private void MenuSmall()
- {
- DoubleAnimation da = new DoubleAnimation();
- da.From = menuWidth;
- da.To = menuWidthDefault;
- da.Duration = TimeSpan.FromSeconds(0.1);
- if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
- {
- if (languageResDic.Contains("image右1"))
- lachuStyle.Style = languageResDic["image右1"] as Style;
- wrapanl_main.BeginAnimation(WidthProperty, da);
- }
- else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
- {
- wrapanl_main.BeginAnimation(HeightProperty, da);
- if (languageResDic.Contains("image左1"))
- lachuStyle.Style = languageResDic["image左1"] as Style;
- }
- }
- }
-
- /// <summary>
- /// 运行Model
- /// </summary>
- public class MenuRunCanvasModel : ObservableObject
- {
- /// <summary>
- /// 菜单Model
- /// </summary>
- private MenuModel _MenuModel;
- public MenuModel MenuModel
- {
- get
- {
- return _MenuModel;
- }
- set
- {
- _MenuModel = value;
- OnPropertyChanged("MenuModel");
- }
- }
- public RelayCommand<object> MenSelectPageCommand { get; set; }
- public Border border { get; set; }
- public MenuRunCanvasModel()
- {
- MenuModel = new MenuModel();
- MenuModel.pageModels = new ObservableCollection<PageModel>();
- MenuModel.pageModels.Add(new PageModel { Name = "首页面", Sort = 0 });
- MenuModel.SelectPageModels = MenuModel.pageModels[0];
- MenSelectPageCommand = new RelayCommand<object>(new Action<object?>(SelectPageHeader));
- }
- /// <summary>
- /// 选中该页
- /// </summary>
- /// <param name="obj"></param>
- public void SelectPageHeader(object obj)
- {
- try
- {
- //MenuModel.SelectPageModels.runCanvas.Destory();
- MenuModel.SelectPageModels = obj as PageModel;
- border.Child = MenuModel.SelectPageModels.runCanvas;
- MenuModel.SelectPageModels.runCanvas.RunSelect();
- }
- catch (Exception ex)
- {
-
- }
- }
- }
- }
|