From e352c4e5f742585e4feeb2ca3183bd4d0282a567 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 14 Dec 2017 14:43:25 +0200 Subject: Implemented new MDI Container Control ! --- .../Managers/RegisteredView.cs | 12 ++- .../Tango.MachineStudio.DB/Views/MainDBView.xaml | 4 +- .../Controls/MdiChild.cs | 58 ++++++++++++ .../Controls/MdiContainerControl.xaml | 75 +++++++++++++++ .../Controls/MdiContainerControl.xaml.cs | 102 +++++++++++++++++++++ .../Converters/PointToMarginConverter.cs | 25 +++++ .../Tango.MachineStudio.Common.csproj | 23 +++-- .../Tango.MachineStudio.Common/UserControl1.xaml | 12 --- .../UserControl1.xaml.cs | 28 ------ .../ViewModels/MainViewVM.cs | 13 +-- .../Tango.SharedUI/Helpers/UIHelper.cs | 66 +++++++++++++ .../Tango.SharedUI/Tango.SharedUI.csproj | 1 + 12 files changed, 355 insertions(+), 64 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs create mode 100644 Software/Visual_Studio/Tango.SharedUI/Helpers/UIHelper.cs (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs index 00c7d341a..fc9051edb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs @@ -1,21 +1,25 @@ -using System; +using MaterialDesignThemes.Wpf; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.Core.Commands; +using Tango.MachineStudio.Common.Controls; namespace Tango.MachineStudio.DB.Managers { - public class RegisteredView + public class RegisteredView : MdiChild { - public String Header { get; set; } - public FrameworkElement View { get; set; } + private static Random rnd = new Random(); + public RelayCommand AddCommand { get; set; } public RegisteredView(String header, FrameworkElement view, Action action) { + Location = new Point(rnd.Next(30, 200), rnd.Next(30, 200)); + Icon = PackIconKind.Table; Header = header; View = view; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml index 5ba51fea8..c7c636d53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml @@ -9,6 +9,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:managers="clr-namespace:Tango.MachineStudio.DB.Managers" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:local="clr-namespace:Tango.MachineStudio.DB.Views" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1270" Background="White" DataContext="{Binding MainViewVM, Source={StaticResource Locator}}"> @@ -44,9 +45,8 @@ - - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs new file mode 100644 index 000000000..469e3fda5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs @@ -0,0 +1,58 @@ +using MaterialDesignThemes.Wpf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Tango.Core.Commands; + +namespace Tango.MachineStudio.Common.Controls +{ + public class MdiChild : DependencyObject + { + public MdiChild() + { + + } + + public MdiChild(String header, FrameworkElement view) : this() + { + Header = header; + View = view; + } + + public PackIconKind Icon + { + get { return (PackIconKind)GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + public static readonly DependencyProperty IconProperty = + DependencyProperty.Register("Icon", typeof(PackIconKind), typeof(MdiChild), new PropertyMetadata(PackIconKind.LaptopWindows)); + + public String Header + { + get { return (String)GetValue(HeaderProperty); } + set { SetValue(HeaderProperty, value); } + } + public static readonly DependencyProperty HeaderProperty = + DependencyProperty.Register("Header", typeof(String), typeof(MdiChild), new PropertyMetadata(null)); + + public FrameworkElement View + { + get { return (FrameworkElement)GetValue(ViewProperty); } + set { SetValue(ViewProperty, value); } + } + public static readonly DependencyProperty ViewProperty = + DependencyProperty.Register("View", typeof(FrameworkElement), typeof(MdiChild), new PropertyMetadata(null)); + + public Point Location + { + get { return (Point)GetValue(LocationProperty); } + set { SetValue(LocationProperty, value); } + } + public static readonly DependencyProperty LocationProperty = + DependencyProperty.Register("Location", typeof(Point), typeof(MdiChild), new PropertyMetadata(new Point())); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml new file mode 100644 index 000000000..3896347fe --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs new file mode 100644 index 000000000..dbf4ee74b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +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; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Common.Controls +{ + /// + /// Interaction logic for MdiContainerControl.xaml + /// + public partial class MdiContainerControl : UserControl + { + private const int MIN_SIZE = 200; + + public MdiContainerControl() + { + InitializeComponent(); + } + + public IEnumerable ItemsSource + { + get { return (IEnumerable)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + public static readonly DependencyProperty ItemsSourceProperty = + DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(MdiContainerControl), new PropertyMetadata(null)); + + private void OnControlDragging(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag(sender); + mdiControl.Location = new Point(mdiControl.Location.X + e.HorizontalChange, mdiControl.Location.Y + e.VerticalChange); + FitCanvas(); + } + + private T GetSenderTag(object sender) where T : class + { + return (T)((sender as FrameworkElement).Tag); + } + + private void FitCanvas() + { + Canvas canvas = GetCanvas(); + canvas.Width = canvas.Children.OfType().Max(x => Canvas.GetLeft(x) + x.ActualWidth); + canvas.Height = canvas.Children.OfType().Max(x => Canvas.GetTop(x) + x.ActualHeight); + } + + private Canvas GetCanvas() + { + return UIHelper.FindChild(itemsControl, "canvas"); + } + + + private void OnControlMouseDown(object sender, MouseButtonEventArgs e) + { + Canvas.SetZIndex(sender as FrameworkElement, GetCanvas().Children.OfType().Max(x => Canvas.GetZIndex(x) + 1)); + } + + private void OnControlSizeRight(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag(sender); + if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth; + if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange; + } + + private void OnControlSizeBottom(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag(sender); + if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight; + if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange; + } + + private void OnControlResize(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag(sender); + + if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight; + if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth; + + if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange; + if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange; + } + + private void OnControlClosed(object sender, RoutedEventArgs e) + { + (ItemsSource as IList).Remove(GetSenderTag(sender)); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs new file mode 100644 index 000000000..e6587b1ee --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Tango.MachineStudio.Common.Converters +{ + public class PointToMarginConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Point p = (Point)value; + return new Thickness(p.X, p.Y, 0, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 0a73c396b..28c2ba817 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -53,19 +53,20 @@ - - MSBuild:Compile + Designer + MSBuild:Compile GlobalVersionInfo.cs + + + MdiContainerControl.xaml + + - - UserControl1.xaml - Code - @@ -91,5 +92,15 @@ Settings.Designer.cs + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} + Tango.SharedUI + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml deleted file mode 100644 index 68210e9f6..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs deleted file mode 100644 index 9028e3810..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -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.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.MachineStudio.Common -{ - /// - /// Interaction logic for UserControl1.xaml - /// - public partial class UserControl1 : UserControl - { - public UserControl1() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 5fb4b436d..e0aff5be3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -61,18 +61,7 @@ namespace Tango.MachineStudio.UI.ViewModels try { Assembly moduleAssembly = null; - String pdbFile = Path.ChangeExtension(file, ".pdb"); - var data = File.ReadAllBytes(file); - - if (File.Exists(pdbFile)) - { - var pdbData = File.ReadAllBytes(pdbFile); - moduleAssembly = Assembly.Load(data, pdbData); - } - else - { - moduleAssembly = Assembly.Load(data); - } + moduleAssembly = Assembly.LoadFrom(file); if (moduleAssembly != null) { diff --git a/Software/Visual_Studio/Tango.SharedUI/Helpers/UIHelper.cs b/Software/Visual_Studio/Tango.SharedUI/Helpers/UIHelper.cs new file mode 100644 index 000000000..12178e428 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Helpers/UIHelper.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; + +namespace Tango.SharedUI.Helpers +{ + public static class UIHelper + { + /// + /// Finds a Child of a given item in the visual tree. + /// + /// A direct parent of the queried item. + /// The type of the queried item. + /// x:Name or Name of child. + /// The first parent item that matches the submitted type parameter. + /// If not matching item can be found, + /// a null parent is being returned. + public static T FindChild(DependencyObject parent, string childName) + where T : DependencyObject + { + // Confirm parent and childName are valid. + if (parent == null) return null; + + T foundChild = null; + + int childrenCount = VisualTreeHelper.GetChildrenCount(parent); + for (int i = 0; i < childrenCount; i++) + { + var child = VisualTreeHelper.GetChild(parent, i); + // If the child is not of the request child type child + T childType = child as T; + if (childType == null) + { + // recursively drill down the tree + foundChild = FindChild(child, childName); + + // If the child is found, break so we do not overwrite the found child. + if (foundChild != null) break; + } + else if (!string.IsNullOrEmpty(childName)) + { + var frameworkElement = child as FrameworkElement; + // If the child's name is set for search + if (frameworkElement != null && frameworkElement.Name == childName) + { + // if the child's name is of the request name + foundChild = (T)child; + break; + } + } + else + { + // child element found. + foundChild = (T)child; + break; + } + } + + return foundChild; + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 0b0716948..228322297 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -99,6 +99,7 @@ ParameterizedEditor.xaml + Code -- cgit v1.3.1