public CostSheetSearchViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, int entityPrimaryKey, OperationMode operationMode, string calledfromparentform = "MainWindow") { try { _userInformation = userInformation; _entityPrimaryKey = entityPrimaryKey; _operationMode = operationMode; _mdiChild = mdiChild; this.calledfromparentform = calledfromparentform.IsNotNullOrEmpty() ? calledfromparentform : "MainWindow"; this.CostSheetSearch = new CostSheetSearchModel(); _costSheetSearchbll = new CostSheetSearchBll(userInformation); this.selectChangeComboCommandCust = new DelegateCommand(this.SelectDataRowCust); this.selectChangeComboCommandCustDwg = new DelegateCommand(this.SelectDataRowCustDwg); this._onSearchCommand = new DelegateCommand(this.SearchCostSheet); this._onPrintCommand = new DelegateCommand(this.PrintCommand); this._onCloseCommand = new DelegateCommand(this.CloseCommand); this.selectChangeComboCommand = new DelegateCommand(this.SelectDataRow); this._modifyCommand = new DelegateCommand <DataRowView>(this.ModifyUsers); CostSheetCount = "Cost Sheet: "; this.DVCostSheetSearch = _costSheetSearchbll.GetPartNumberDetails(); LoadFormData(); _costSheetSearchbll.GetCustNameDetails(CostSheetSearch); _costSheetSearchbll.GetCustDwg(CostSheetSearch); PrintEnabled = false; SetdropDownItems(); } catch (Exception ex) { throw ex.LogException(); } }
public DDPerformanceViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, System.Windows.Controls.DataGrid dgDDPerformance) { try { _userInformation = userInformation; _mdiChild = mdiChild; _ddPerformanceBll = new DDPerformanceBll(_userInformation); this.costSheetReceivedCommand = new DelegateCommand(this.costSheetReceived); this.costSheetCompletedCommand = new DelegateCommand(this.costSheetCompleted); this.partNumbersAllottedCommand = new DelegateCommand(this.partNumbersAllotted); this.documentsReleasedCommand = new DelegateCommand(this.documentsReleased); this.samplesSubmittedCommand = new DelegateCommand(this.samplesSubmitted); this.refreshCommand = new DelegateCommand(this.Refresh); this.performanceSummaryCommand = new DelegateCommand(this.PerformanceSummary); this.mOPCommand = new DelegateCommand(this.MOPGraph); this.showECNCommand = new DelegateCommand(this.ShowECN); this.showPCNCommand = new DelegateCommand(this.ShowPCN); this.showDesignersCommand = new DelegateCommand(this.ShowDesigners); this.printReportCommand = new DelegateCommand(this.PrintReport); this.showProductInformationCommand = new DelegateCommand(this.ShowProductInformation); StartDate = Convert.ToDateTime("01/" + DateTime.Now.ToString("MM/yyyy")); EndDate = DateTime.Now; _perfOption = performanceOption.CostSheetReceived; DgDDPerformance = dgDDPerformance; SetCombo(); Refresh(); } catch (Exception ex) { throw ex.LogException(); } }
/// <summary> /// Dependency property event once the maximize box value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void MaximizeBoxValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { MdiChild mdiChild = (MdiChild)sender; bool visible = (bool)e.NewValue; if (visible) { bool minimizeVisible = true; if (mdiChild.minimizeButton != null) { minimizeVisible = mdiChild.minimizeButton.Visibility == Visibility.Visible; } if (mdiChild.maximizeButton != null) { mdiChild.maximizeButton.IsEnabled = true; } if (!minimizeVisible) { if (mdiChild.maximizeButton != null) { mdiChild.minimizeButton.Visibility = Visibility.Visible; } if (mdiChild.maximizeButton != null) { mdiChild.maximizeButton.Visibility = Visibility.Visible; } } } else { bool minimizeEnabled = true; if (mdiChild.minimizeButton != null) { minimizeEnabled = mdiChild.minimizeButton.IsEnabled; } if (mdiChild.maximizeButton != null) { mdiChild.maximizeButton.IsEnabled = false; } if (!minimizeEnabled) { if (mdiChild.maximizeButton != null) { mdiChild.minimizeButton.Visibility = Visibility.Hidden; } if (mdiChild.maximizeButton != null) { mdiChild.maximizeButton.Visibility = Visibility.Hidden; } } } }
/// <summary> /// Invalidates the size checking to see if the furthest /// child point exceeds the current height and width. /// </summary> internal void InvalidateSize() { Point largestPoint = new Point(0, 0); for (int i = 0; i < windowCanvas.Children.Count; i++) { MdiChild mdiChild = (MdiChild)windowCanvas.Children[i]; Point farPosition = new Point(Canvas.GetLeft(mdiChild) + mdiChild.ActualWidth, Canvas.GetTop(mdiChild) + mdiChild.ActualHeight); if (farPosition.X > largestPoint.X) { largestPoint.X = farPosition.X; } if (farPosition.Y > largestPoint.Y) { largestPoint.Y = farPosition.Y; } } if (windowCanvas.Width != largestPoint.X) { windowCanvas.Width = largestPoint.X; } if (windowCanvas.Height != largestPoint.Y) { windowCanvas.Height = largestPoint.Y; } }
public static UserControl OpenTab(MdiContainer container, Type type, string title, bool canDuplicate) { if (type != null) { if (!canDuplicate) { var type_string = type.ToString(); var first = container.Children.FirstOrDefault(o => o.Content.GetType().ToString() == type_string); if (first != null) { first.Focus(); first.WindowState = WindowState.Normal; return(null); } } else { title += string.Format(" - {0}", ++_id); } var child = new WPF.MDI.MdiChild() { Title = title, Resizable = false }; var content = (UserControl)Activator.CreateInstance(type); content.Tag = child; child.Tag = container; child.Content = content; container.Children.Add(child); return(content); } return(null); }
/// <summary> /// Focuses a child and brings it into view. /// </summary> /// <param name="mdiChild">The MDI child.</param> internal static void Focus(MdiChild mdiChild) { if (mdiChild == null || mdiChild.Container == null) { return; } mdiChild.Container._buttons.Child = mdiChild.Buttons; int maxZindex = 0; for (int i = 0; i < mdiChild.Container.Children.Count; i++) { int zindex = Panel.GetZIndex(mdiChild.Container.Children[i]); if (zindex > maxZindex) { maxZindex = zindex; } if (mdiChild.Container.Children[i] != mdiChild) { mdiChild.Container.Children[i].Focused = false; } else { mdiChild.Focused = true; } } Panel.SetZIndex(mdiChild, maxZindex + 1); }
/// <summary> /// Invalidates the size checking to see if the furthest /// child point exceeds the current height and width. /// </summary> internal void InvalidateSize() { Point largestPoint = new Point(0, 0); for (int i = 0; i < Children.Count; i++) { MdiChild mdiChild = Children[i]; Point farPosition = new Point(mdiChild.Position.X + mdiChild.Width, mdiChild.Position.Y + mdiChild.Height); if (farPosition.X > largestPoint.X) { largestPoint.X = farPosition.X; } if (farPosition.Y > largestPoint.Y) { largestPoint.Y = farPosition.Y; } } if (_windowCanvas.Width != largestPoint.X) { _windowCanvas.Width = largestPoint.X; } if (_windowCanvas.Height != largestPoint.Y) { _windowCanvas.Height = largestPoint.Y; } }
/// <summary> /// Focuses a child and brings it into view. /// FUTURE: Look into how ZIndex works. /// </summary> /// <param name="mdiChild">The MDI child.</param> internal void Focus(MdiChild mdiChild) { for (var i = 0; i < _windowCanvas.Children.Count; i++) { ((MdiChild)_windowCanvas.Children[i]).Focused = (_windowCanvas.Children[i] == mdiChild && _windowCanvas.Children[i].GetType() == typeof(MdiChild)); } _windowCanvas.Children.Remove(mdiChild); _windowCanvas.Children.Add(mdiChild); }
/// <summary> /// Handles the CollectionChanged event of the Children control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> private void Children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { MdiChild mdiChild = Children[e.NewStartingIndex], topChild = ActiveMdiChild; if (topChild != null && topChild.WindowState == WindowState.Maximized) { mdiChild.Loaded += (s, a) => mdiChild.WindowState = WindowState.Maximized; } mdiChild.Loaded += (s, a) => ActiveMdiChild = mdiChild; if (mdiChild.Position.X < 0 || mdiChild.Position.Y < 0) { mdiChild.Position = new Point(_windowOffset, _windowOffset); } _windowCanvas.Children.Add(mdiChild); _windowOffset += WindowOffset; if (_windowOffset + mdiChild.Width > ActualWidth) { _windowOffset = 0; } if (_windowOffset + mdiChild.Height > ActualHeight) { _windowOffset = 0; } } break; case NotifyCollectionChangedAction.Remove: { MdiChild oldChild = (MdiChild)e.OldItems[0]; _windowCanvas.Children.Remove(oldChild); MdiChild newChild = GetTopChild(); ActiveMdiChild = newChild; if (newChild != null && oldChild.WindowState == WindowState.Maximized) { newChild.WindowState = WindowState.Maximized; } } break; case NotifyCollectionChangedAction.Reset: _windowCanvas.Children.Clear(); break; } InvalidateSize(); }
/// <summary> /// Dependency property event once the focused value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void FocusedValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue == (bool)e.OldValue) { return; } MdiChild mdiChild = (MdiChild)sender; bool focused = (bool)e.NewValue; mdiChild.RaiseEvent(focused ? new RoutedEventArgs(GotFocusEvent, mdiChild) : new RoutedEventArgs(LostFocusEvent, mdiChild)); }
public frmCoatingMaster(string formName, WPF.MDI.MdiChild me) { InitializeComponent(); this._formName = formName; OperationMasterViewModel vm = new OperationMasterViewModel(_formName); this.DataContext = vm; me.Closing += vm.CloseMethod; if (vm.CloseAction == null) { vm.CloseAction = new Action(() => me.Close()); } }
/// <summary> /// Dependency property event once the position value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void PositionValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if ((Point)e.NewValue == (Point)e.OldValue) { return; } MdiChild mdiChild = (MdiChild)sender; Point newPosition = (Point)e.NewValue; Canvas.SetTop(mdiChild, newPosition.Y < 0 ? 0 : newPosition.Y); Canvas.SetLeft(mdiChild, newPosition.X < 0 ? 0 : newPosition.X); }
/// <summary> /// Handles the CollectionChanged event of the Children control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> private void Children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { MdiChild mdiChild = Children[e.NewStartingIndex], topChild = GetTopChild(); if (topChild != null && topChild.WindowState == WindowState.Maximized) { mdiChild.Loaded += (s, a) => mdiChild.WindowState = WindowState.Maximized; } mdiChild.Position = new Point(_windowOffset, _windowOffset); _windowCanvas.Children.Add(mdiChild); mdiChild.Loaded += (s, a) => Focus(mdiChild); _windowOffset += WindowOffset; if (InnerWidth > 0 && InnerHeight > 0) { if (_windowOffset + mdiChild.Width > InnerWidth) { _windowOffset = 0; } if (_windowOffset + mdiChild.Height > InnerHeight) { _windowOffset = 0; } } mdiChild.CanDragOut = CanDragOut; } break; case NotifyCollectionChangedAction.Remove: { _windowCanvas.Children.Remove((MdiChild)e.OldItems[0]); Focus(GetTopChild()); } break; case NotifyCollectionChangedAction.Reset: _windowCanvas.Children.Clear(); break; } InvalidateSize(); }
public frmToolsInfo(UserInformation userInformation, WPF.MDI.MdiChild mdiChild) { InitializeComponent(); ToolInfoViewModel vm = new ToolInfoViewModel(); this.DataContext = vm; mdiChild.Closing += vm.CloseMethod; vm.PreviewImage = imgPhoto; vm.DgToolInfo = rpdDataGrid; if (vm.CloseAction == null) { vm.CloseAction = new Action(() => mdiChild.Close()); } }
static void MdiChild_KeyDown(object sender, KeyEventArgs e) { MdiChild mdiChild = (MdiChild)sender; switch (e.Key) { case Key.F4: if (e.KeyboardDevice.Modifiers == ModifierKeys.Alt) { mdiChild.Close(); e.Handled = true; } break; } }
public frmOperationMain(string formName, WPF.MDI.MdiChild me) { InitializeComponent(); this._formName = formName; // FocusManager.SetFocusedElement(this, txt_operDesc); OperationMasterViewModel vm = new OperationMasterViewModel(_formName); this.DataContext = vm; me.Closing += vm.CloseMethod; if (vm.CloseAction == null) { vm.CloseAction = new Action(() => me.Close()); } }
public ReportPendingPartNumberStatusViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, bool refreshOnLoad = false, string title = REPORT_TITLE) { _userInformation = userInformation; this.mdiChild = mdiChild; bll = new ReportPendingPartNumberStatus(userInformation); MandatoryFields = new ReportPendingPartNumberStatusModel(); MandatoryFields.GRID_TITLE = REPORT_TITLE; this.printCommand = new DelegateCommand(this.PrintSubmitCommand); this.refreshCommand = new DelegateCommand(this.RefreshSubmitCommand); this.closeCommand = new DelegateCommand(this.Close); this.mouseDoubleClickGrdMeasuringDetails = new DelegateCommand <DataRowView>(this.SelectDataRowMouseDoubleClickMeasuringDetails); isFocusedDocRel = true; }
//private readonly ICommand mousecombocommand; //public ICommand MouseComboCommand { get { return this.mousecombocommand; } } public ReportMISFeatureWiseViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild, PCCS feature = null, PCCS feature1 = null, PCCS feature2 = null, PCCS specification = null, PRD_MAST productMaster = null, bool refreshOnLoad = false, string title = REPORT_TITLE) { _userInformation = userInformation; this.mdiChild = mdiChild; bll = new ReportMISFeatureWise(userInformation); MandatoryFields = new ReportMISFeatureWiseModel(); MandatoryFields.GRID_TITLE = REPORT_TITLE; this.printCommand = new DelegateCommand(this.PrintSubmitCommand); //this.mousecombocommand = new DelegateCommand(this.MouseDblClick); this.refreshCommand = new DelegateCommand(this.RefreshSubmitCommand); this.exportToExcelCommand = new DelegateCommand(this.ExportToExcelSubmitCommand); //FeatureDataSource = bll.GetFeature().ToDataTable<PCCS>().DefaultView; FeatureDataSource = bll.GetFeatureDataTable().DefaultView; this._featureSelectedItemChangedCommand = new DelegateCommand(this.FeatureChanged); FeatureDropDownItems = new ObservableCollection <DropdownColumns>() { new DropdownColumns() { ColumnName = "FEATURE", ColumnDesc = "Feature", ColumnWidth = "1*" }, }; Feature1DataSource = FeatureDataSource.Table.Copy().DefaultView; this._feature1SelectedItemChangedCommand = new DelegateCommand(this.Feature1Changed); Feature1DropDownItems = new ObservableCollection <DropdownColumns>() { new DropdownColumns() { ColumnName = "FEATURE", ColumnDesc = "Feature", ColumnWidth = "1*" }, }; Feature2DataSource = FeatureDataSource.Table.Copy().DefaultView; this._feature2SelectedItemChangedCommand = new DelegateCommand(this.Feature2Changed); Feature2DropDownItems = new ObservableCollection <DropdownColumns>() { new DropdownColumns() { ColumnName = "FEATURE", ColumnDesc = "Feature", ColumnWidth = "1*" }, }; }
/// <summary> /// Focuses a child and brings it into view. /// TODO: Look into how ZIndex works. /// </summary> /// <param name="mdiChild">The MDI child.</param> internal void Focus(MdiChild mdiChild) { for (int i = 0; i < windowCanvas.Children.Count; i++) { if (windowCanvas.Children[i] != mdiChild && windowCanvas.Children[i].GetType() == typeof(MdiChild)) { ((MdiChild)windowCanvas.Children[i]).Focused = false; } else { ((MdiChild)windowCanvas.Children[i]).Focused = true; } } windowCanvas.Children.Remove(mdiChild); windowCanvas.Children.Add(mdiChild); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.LayoutRoot = ((System.Windows.Controls.Grid)(target)); return; case 2: this.Container = ((WPF.MDI.MdiContainer)(target)); return; case 3: this.ChildWindowContent = ((WPF.MDI.MdiChild)(target)); return; } this._contentLoaded = true; }
public APQPViewModel(UserInformation userInformation, WPF.MDI.MdiChild mdiChild) { try { _aPQPBll = new APQPBll(userInformation); DvAPQP = _aPQPBll.GetApQpChart("").DefaultView; PartNoCombo = _aPQPBll.GetPartNoDetails(); SetdropDownItems(); this.selectChangeComboCommandPartNo = new DelegateCommand(this.SelectDataRowPart); this.saveCommand = new DelegateCommand(this.Save); this.printReportCommand = new DelegateCommand(this.PrintReport); PartNo = ""; } catch (Exception ex) { throw ex.LogException(); } }
/// <summary> /// Dependency property event once the focused mdi child has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void ActiveMdiChildValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { MdiContainer mdiContainer = (MdiContainer)sender; MdiChild newChild = (MdiChild)e.NewValue, oldChild = (MdiChild)e.OldValue; if (newChild == null || newChild == oldChild) { return; } if (oldChild != null && oldChild.WindowState == WindowState.Maximized) { newChild.WindowState = WindowState.Maximized; } int maxZindex = 0; for (int i = 0; i < mdiContainer.Children.Count; i++) { int zindex = Panel.GetZIndex(mdiContainer.Children[i]); if (zindex > maxZindex) { maxZindex = zindex; } if (mdiContainer.Children[i] != newChild) { mdiContainer.Children[i].Focused = false; } else { newChild.Focused = true; } } Panel.SetZIndex(newChild, maxZindex + 1); if (mdiContainer.MdiChildTitleChanged != null) { mdiContainer.MdiChildTitleChanged(mdiContainer, new RoutedEventArgs()); } }
/// <summary> /// Dependency property event once the focused value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void FocusedValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue == (bool)e.OldValue) { return; } MdiChild mdiChild = (MdiChild)sender; bool focused = (bool)e.NewValue; if (focused) { mdiChild.Dispatcher.BeginInvoke(new Func <IInputElement, IInputElement>(Keyboard.Focus), System.Windows.Threading.DispatcherPriority.ApplicationIdle, mdiChild.Content); mdiChild.RaiseEvent(new RoutedEventArgs(GotFocusEvent, mdiChild)); } else { mdiChild.RaiseEvent(new RoutedEventArgs(LostFocusEvent, mdiChild)); } }
/// <summary> /// Dependency property event once the close box value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void CloseBoxValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { MdiChild mdiChild = (MdiChild)sender; bool visible = (bool)e.NewValue; if (visible) { if ((mdiChild.closeButton != null) && (mdiChild.closeButton.Visibility != Visibility.Visible)) { mdiChild.closeButton.Visibility = Visibility.Visible; } } else { if ((mdiChild.closeButton != null) && (mdiChild.closeButton.Visibility == Visibility.Visible)) { mdiChild.closeButton.Visibility = Visibility.Collapsed; } } }
MdiChild CreateWindow(UIElement content, string header) { var grid = new Grid(); var transitionControl = new TransitionContentControl(); transitionControl.AnimationStrategy = new ModalAnimationStrategy(500.MilliSeconds(), grid); grid.Children.Add(transitionControl); grid.Children.Add(content); Panel.SetZIndex(transitionControl, 100); var child = new MdiChild { Title = header, Content = grid, Background = Brushes.White, Height = 600, Width = 600 }; return child; }
/// <summary> /// Handles the SizeChanged event of the MdiContainer control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.SizeChangedEventArgs"/> instance containing the event data.</param> private void MdiContainer_SizeChanged(object sender, SizeChangedEventArgs e) { if (Children.Count == 0) { return; } for (int i = 0; i < Children.Count; i++) { MdiChild mdiChild = Children[i]; if (mdiChild.WindowState == WindowState.Maximized) { mdiChild.Width = ActualWidth; mdiChild.Height = ActualHeight; } if (mdiChild.WindowState == WindowState.Minimized) { mdiChild.Position = new Point(mdiChild.Position.X, mdiChild.Position.Y + e.NewSize.Height - e.PreviousSize.Height); } } }
/// <summary> /// Handles the CollectionChanged event of the Children control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> private void Children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { MdiChild mdiChild = (MdiChild)Children[e.NewStartingIndex]; Canvas.SetLeft(mdiChild, (windowCanvas.Children.Count * 25) + 2); Canvas.SetTop(mdiChild, (windowCanvas.Children.Count * 25) + 2); if (windowCanvas.Children.Count == 0 || ((MdiChild)windowCanvas.Children[windowCanvas.Children.Count - 1]).WindowState != WindowState.Maximized) { windowCanvas.Children.Add(mdiChild); mdiChild.Loaded += (s, a) => { Focus(mdiChild); }; } else { windowCanvas.Children.Insert(windowCanvas.Children.Count - 1, mdiChild); } } break; case NotifyCollectionChangedAction.Remove: { windowCanvas.Children.Remove((MdiChild)e.OldItems[0]); if (windowCanvas.Children.Count > 0) { Focus((MdiChild)windowCanvas.Children[windowCanvas.Children.Count - 1]); } } break; } }
/// <summary> /// Handles the CollectionChanged event of the Children control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> private void Children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: { MdiChild child = Children[e.NewStartingIndex]; //if (IsFormAlreadyOpen(child.Title) == true) //{ // _windowCanvas.Children.Remove(Children[e.NewStartingIndex]); // Children.RemoveAt(e.NewStartingIndex); // Focus(GetFormAlreadyOpened(child.Title)); // break; //} MdiChild mdiChild = Children[e.NewStartingIndex], topChild = GetTopChild(); if (topChild != null && topChild.WindowState == WindowState.Maximized) { mdiChild.Loaded += (s, a) => mdiChild.WindowState = WindowState.Maximized; } //mdiChild.Position = new Point(_windowOffset, _windowOffset); //_windowCanvas.Children.Add(mdiChild); //mdiChild.Loaded += (s, a) => Focus(mdiChild); //_windowOffset += WindowOffset; //if (_windowOffset + mdiChild.Width > ActualWidth) // _windowOffset = 0; //if (_windowOffset + mdiChild.Height > ActualHeight) // _windowOffset = 0; if (mdiChild.Icon == null) { var uriSource = new Uri(@"/WPF.MDI;component/Images/logo.ico", UriKind.Relative); mdiChild.Icon = new BitmapImage(uriSource); } _windowOffsetLeft = (ActualWidth - mdiChild.Width) / 2; _windowOffsetTop = ((ActualHeight - 30) - mdiChild.Height) / 2; mdiChild.Position = new Point(_windowOffsetLeft, _windowOffsetTop); _windowCanvas.Children.Add(mdiChild); mdiChild.Loaded += (s, a) => Focus(mdiChild); _windowOffsetLeft += WindowOffset; _windowOffsetTop += WindowOffset; if (_windowOffsetLeft + mdiChild.Width > ActualWidth) { _windowOffsetLeft = 0; } if (_windowOffsetTop + mdiChild.Height > ActualHeight) { _windowOffsetTop = 0; } } break; case NotifyCollectionChangedAction.Remove: { _windowCanvas.Children.Remove((MdiChild)e.OldItems[0]); Focus(GetTopChild()); } break; case NotifyCollectionChangedAction.Reset: _windowCanvas.Children.Clear(); break; } InvalidateSize(); }
/// <summary> /// Dependency property event once the windows state value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void WindowStateValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { MdiChild mdiChild = (MdiChild)sender; MdiContainer mdiContainer = mdiChild.Container; WindowState previousWindowState = (WindowState)e.OldValue; WindowState windowState = (WindowState)e.NewValue; if (mdiChild.Container == null || previousWindowState == windowState) { return; } if (previousWindowState == WindowState.Maximized) { if (mdiContainer.ActiveMdiChild.WindowState != WindowState.Maximized) { for (int i = 0; i < mdiContainer.Children.Count; i++) { if (mdiContainer.Children[i] != mdiChild && mdiContainer.Children[i].WindowState == WindowState.Maximized && mdiContainer.Children[i].MaximizeBox) { mdiContainer.Children[i].WindowState = WindowState.Normal; } } ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1]; sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; } mdiChild.Buttons.Children.Clear(); mdiChild.Buttons = null; mdiChild.buttonsPanel.Children.Add(mdiChild.minimizeButton); mdiChild.buttonsPanel.Children.Add(mdiChild.maximizeButton); mdiChild.buttonsPanel.Children.Add(mdiChild.closeButton); } if (previousWindowState == WindowState.Minimized) { mdiChild.minimizedPosition = mdiChild.Position; } switch (windowState) { case WindowState.Normal: { mdiChild.Position = new Point(mdiChild.originalDimension.X, mdiChild.originalDimension.Y); mdiChild.Width = mdiChild.originalDimension.Width; mdiChild.Height = mdiChild.originalDimension.Height; } break; case WindowState.Minimized: { if (previousWindowState == WindowState.Normal) { mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight); } double newLeft, newTop; if (mdiChild.minimizedPosition.X >= 0 || mdiChild.minimizedPosition.Y >= 0) { newLeft = mdiChild.minimizedPosition.X; newTop = mdiChild.minimizedPosition.Y; } else { List <Rect> minimizedWindows = new List <Rect>(); for (int i = 0; i < mdiContainer.Children.Count; i++) { MdiChild child = mdiContainer.Children[i]; if (child != mdiChild && child.WindowState == WindowState.Minimized) { minimizedWindows.Add(new Rect(child.Position.X, mdiContainer.InnerHeight - child.Position.Y, child.Width, child.Height)); } } Rect newWindowPlace; bool occupied = true; int count = 0, capacity = Convert.ToInt32(mdiContainer.ActualWidth) / MdiChild.MinimizedWidth; do { int row = count / capacity + 1, col = count % capacity; newTop = MdiChild.MinimizedHeight * row; newLeft = MdiChild.MinimizedWidth * col; newWindowPlace = new Rect(newLeft, newTop, MdiChild.MinimizedWidth, MdiChild.MinimizedHeight); occupied = false; foreach (Rect rect in minimizedWindows) { Rect intersection = rect; intersection.Intersect(newWindowPlace); if (intersection != Rect.Empty && intersection.Width > 0 && intersection.Height > 0) { occupied = true; break; } } count++; // TODO: handle negative Canvas coordinates somehow. if (newTop < 0) { // ugly workaround for now. newTop = 0; occupied = false; } } while (occupied); newTop = mdiContainer.InnerHeight - newTop; } mdiChild.Position = new Point(newLeft, newTop); mdiChild.Width = MdiChild.MinimizedWidth; mdiChild.Height = MdiChild.MinimizedHeight; } break; case WindowState.Maximized: { if (previousWindowState == WindowState.Normal) { mdiChild.originalDimension = new Rect(mdiChild.Position.X, mdiChild.Position.Y, mdiChild.ActualWidth, mdiChild.ActualHeight); } mdiChild.NonMaximizedState = previousWindowState; mdiChild.buttonsPanel.Children.Clear(); StackPanel sp = new StackPanel { Orientation = Orientation.Horizontal }; sp.Children.Add(mdiChild.minimizeButton); sp.Children.Add(mdiChild.maximizeButton); sp.Children.Add(mdiChild.closeButton); mdiChild.Buttons = sp; mdiChild.Position = new Point(0, 0); mdiChild.Width = mdiContainer.ActualWidth; mdiChild.Height = mdiContainer.InnerHeight - 2; // ContentBorder.BorderThickness="1" in template ScrollViewer sv = (ScrollViewer)((Grid)mdiContainer.Content).Children[1]; sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; sv.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; } break; } if (mdiContainer.ActiveMdiChild == mdiChild) { mdiContainer.Buttons = mdiChild.Buttons; } mdiContainer.InvalidateSize(); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.Container = ((WPF.MDI.MdiContainer)(target)); return; case 2: #line 11 "..\..\Main.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.AddWindow_Click); #line default #line hidden return; case 3: #line 12 "..\..\Main.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.AddFixedWindow_Click); #line default #line hidden return; case 4: #line 13 "..\..\Main.xaml" ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.AddScrollWindow_Click); #line default #line hidden return; case 5: this.Generic = ((System.Windows.Controls.MenuItem)(target)); #line 16 "..\..\Main.xaml" this.Generic.Click += new System.Windows.RoutedEventHandler(this.Generic_Click); #line default #line hidden return; case 6: this.Luna = ((System.Windows.Controls.MenuItem)(target)); #line 17 "..\..\Main.xaml" this.Luna.Click += new System.Windows.RoutedEventHandler(this.Luna_Click); #line default #line hidden return; case 7: this.Aero = ((System.Windows.Controls.MenuItem)(target)); #line 18 "..\..\Main.xaml" this.Aero.Click += new System.Windows.RoutedEventHandler(this.Aero_Click); #line default #line hidden return; case 8: this.WindowsMenu = ((System.Windows.Controls.MenuItem)(target)); return; case 9: this.Window1 = ((WPF.MDI.MdiChild)(target)); return; case 10: this.DisableMinimize = ((System.Windows.Controls.Button)(target)); #line 26 "..\..\Main.xaml" this.DisableMinimize.Click += new System.Windows.RoutedEventHandler(this.DisableMinimize_Click); #line default #line hidden return; case 11: this.EnableMinimize = ((System.Windows.Controls.Button)(target)); #line 27 "..\..\Main.xaml" this.EnableMinimize.Click += new System.Windows.RoutedEventHandler(this.EnableMinimize_Click); #line default #line hidden return; case 12: this.DisableMaximize = ((System.Windows.Controls.Button)(target)); #line 28 "..\..\Main.xaml" this.DisableMaximize.Click += new System.Windows.RoutedEventHandler(this.DisableMaximize_Click); #line default #line hidden return; case 13: this.EnableMaximize = ((System.Windows.Controls.Button)(target)); #line 29 "..\..\Main.xaml" this.EnableMaximize.Click += new System.Windows.RoutedEventHandler(this.EnableMaximize_Click); #line default #line hidden return; case 14: this.ShowIcon = ((System.Windows.Controls.Button)(target)); #line 30 "..\..\Main.xaml" this.ShowIcon.Click += new System.Windows.RoutedEventHandler(this.ShowIcon_Click); #line default #line hidden return; case 15: this.HideIcon = ((System.Windows.Controls.Button)(target)); #line 31 "..\..\Main.xaml" this.HideIcon.Click += new System.Windows.RoutedEventHandler(this.HideIcon_Click); #line default #line hidden return; } this._contentLoaded = true; }
/// <summary> /// Dependency property event once the MDI layout value has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param> private static void MdiLayoutValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { MdiContainer mdiContainer = (MdiContainer)sender; MdiLayout value = (MdiLayout)e.NewValue; if (value == MdiLayout.ArrangeIcons || mdiContainer.Children.Count < 1) { return; } // 1. WindowState.Maximized -> WindowState.Normal List <MdiChild> minimizedWindows = new List <MdiChild>(), normalWindows = new List <MdiChild>(); foreach (MdiChild mdiChild in mdiContainer.Children) { switch (mdiChild.WindowState) { case WindowState.Minimized: minimizedWindows.Add(mdiChild); break; case WindowState.Maximized: mdiChild.WindowState = WindowState.Normal; normalWindows.Add(mdiChild); break; default: normalWindows.Add(mdiChild); break; } } minimizedWindows.Sort(new MdiChildComparer()); normalWindows.Sort(new MdiChildComparer()); // 2. Arrange minimized windows double containerHeight = mdiContainer.InnerHeight; for (int i = 0; i < minimizedWindows.Count; i++) { MdiChild mdiChild = minimizedWindows[i]; int capacity = Convert.ToInt32(mdiContainer.ActualWidth / MdiChild.MinimizedWidth), row = i / capacity + 1, col = i % capacity; containerHeight = mdiContainer.InnerHeight - MdiChild.MinimizedHeight * row; double newLeft = MdiChild.MinimizedWidth * col; mdiChild.Position = new Point(newLeft, containerHeight); } // 3. Resize & arrange normal windows switch (value) { case MdiLayout.Cascade: { double newWidth = mdiContainer.ActualWidth - (int)(mdiContainer.ActualWidth * 0.20); //Width - 20% double newHeight = containerHeight - (int)(containerHeight * 0.30); //Height - 30% double CurrentWindowOffset = 0; foreach (MdiChild mdiChild in normalWindows) { if (mdiChild.Resizable) { mdiChild.Width = newWidth; mdiChild.Height = newHeight; } mdiChild.Position = new Point(CurrentWindowOffset, CurrentWindowOffset); CurrentWindowOffset += WindowOffset; if (CurrentWindowOffset + mdiChild.Width > mdiContainer.ActualWidth) { CurrentWindowOffset = 0; } if (CurrentWindowOffset + mdiChild.Height > containerHeight) { CurrentWindowOffset = 0; } } } break; case MdiLayout.TileHorizontal: { double cols = Math.Sqrt(normalWindows.Count), rows = normalWindows.Count / cols; List <double> col_count = new List <double>(); // windows per column for (int i = 0; i < cols; i++) { if (normalWindows.Count % cols > cols - i - 1) { col_count.Add(rows + 1); } else { col_count.Add(rows); } } double newWidth = mdiContainer.ActualWidth / cols, newHeight = containerHeight / col_count[0], offsetTop = 0, offsetLeft = 0; double prev_count = 0; for (int i = 0, col_index = 0; i < normalWindows.Count; i++) { if (i >= prev_count + col_count[col_index]) { prev_count += col_count[col_index++]; offsetLeft += newWidth; offsetTop = 0; newHeight = containerHeight / col_count[col_index]; } MdiChild mdiChild = normalWindows[i]; if (mdiChild.Resizable) { mdiChild.Width = newWidth; mdiChild.Height = newHeight; } mdiChild.Position = new Point(offsetLeft, offsetTop); offsetTop += newHeight; } } break; case MdiLayout.TileVertical: { double rows = Math.Sqrt(normalWindows.Count), cols = normalWindows.Count / rows; List <double> col_count = new List <double>(); // windows per column for (int i = 0; i < cols; i++) { if (normalWindows.Count % cols > cols - i - 1) { col_count.Add(rows + 1); } else { col_count.Add(rows); } } double newWidth = mdiContainer.ActualWidth / cols, newHeight = containerHeight / col_count[0], offsetTop = 0, offsetLeft = 0; double prev_count = 0; for (int i = 0, col_index = 0; i < normalWindows.Count; i++) { if (i >= prev_count + col_count[col_index]) { prev_count += col_count[col_index++]; offsetLeft += newWidth; offsetTop = 0; newHeight = containerHeight / col_count[col_index]; } MdiChild mdiChild = normalWindows[i]; if (mdiChild.Resizable) { mdiChild.Width = newWidth; mdiChild.Height = newHeight; } mdiChild.Position = new Point(offsetLeft, offsetTop); offsetTop += newHeight; } } break; } mdiContainer.InvalidateSize(); mdiContainer.MdiLayout = MdiLayout.ArrangeIcons; }