/// <summary> /// Show or expand popup</summary> /// <param name="dockContent">Dock content</param> internal void ShowPopup(DockContent dockContent) { if (PART_Popup.IsOpen) { if (!((DockedWindow)PART_Popup.Content).HasChild(dockContent)) { ClosePopup(); } else { return; } } ContentSettings settings = dockContent.Settings; switch (Orientation) { case Orientation.Horizontal: PART_Popup.MaxWidth = RenderSize.Width; PART_Popup.MaxHeight = 0.75 * Math.Min(Root.RenderSize.Height, System.Windows.SystemParameters.PrimaryScreenHeight); PART_Popup.Width = RenderSize.Width; PART_Popup.Height = Math.Min(settings.Size.Height + 25, PART_Popup.MaxHeight); break; case Orientation.Vertical: PART_Popup.MaxWidth = 0.75 * Math.Min(Root.RenderSize.Width, System.Windows.SystemParameters.PrimaryScreenWidth); PART_Popup.MaxHeight = RenderSize.Height; PART_Popup.Width = Math.Min(settings.Size.Width + 7, PART_Popup.MaxWidth); PART_Popup.Height = RenderSize.Height; break; } DockedWindow window = new DockedWindow(Root, dockContent); window.Closing += Window_Closing; window.Focused = true; window.IsCollapsed = true; PART_Popup.Content = window; PART_Popup.Tag = dockContent; BooleanAnimationUsingKeyFrames booleanAnimation = new BooleanAnimationUsingKeyFrames(); booleanAnimation.Duration = TimeSpan.FromSeconds(0.1); booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( false, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0))) // KeyTime ); booleanAnimation.KeyFrames.Add( new DiscreteBooleanKeyFrame( true, // Target value (KeyValue) KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.1))) // KeyTime ); PART_Popup.IsOpen = true; Root.Focus(dockContent); m_timer.Start(); }
/// <summary> /// Callback function for dock content changing</summary> /// <param name="sender">Event sender DependencyObject</param> /// <param name="args">Dependency property changed event arguments</param> public static void DockedContentPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { DockedWindow window = null; if ((window = sender as DockedWindow) != null) { IDockContent content; if ((content = args.OldValue as IDockContent) != null) { content.IsFocusedChanged -= window.DockContent_IsFocusChanged; } if ((content = args.NewValue as IDockContent) != null) { content.IsFocusedChanged += window.DockContent_IsFocusChanged; } } }
/// <summary> /// Close popup</summary> private void ClosePopup() { PART_Popup.IsOpen = false; DockedWindow window = PART_Popup.Content as DockedWindow; if (window != null) { DockContent content = (DockContent)PART_Popup.Tag; window.Closing -= Window_Closing; window.Close(); content.IsVisible = true; PART_Popup.Tag = null; PART_Popup.Content = null; } foreach (SideBarButton button in Items) { button.IsChecked = false; } }
public void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToFollowing(this.GetType().Name)) { String s = reader.GetAttribute(Orientation.GetType().Name); m_orientation = (Orientation)(Enum.Parse(Orientation.GetType(), s)); switch (m_orientation) { case Orientation.Horizontal: if (reader.ReadToDescendant("Column")) { RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Height)); do { double width = double.Parse(reader.GetAttribute("Width")); IDockLayout layout = null; reader.ReadStartElement(); if (reader.LocalName == typeof(DockedWindow).Name) { DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree()); layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null; reader.ReadEndElement(); } else if (reader.LocalName == typeof(GridLayout).Name) { GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree()); layout = gridLayout.Layouts.Count > 0 ? gridLayout : null; reader.ReadEndElement(); } if (layout != null) { if (Children.Count > 0) { ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Add(NewGridSplitter(Orientation)); } ColumnDefinitions.Add(NewColumnDefinition(new GridLength(width, GridUnitType.Star), m_minGridSize.Width)); m_children.Add(layout); Children.Add((FrameworkElement)layout); } } while (reader.ReadToNextSibling("Column")); } break; case Orientation.Vertical: if (reader.ReadToDescendant("Row")) { ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Width)); do { double height = double.Parse(reader.GetAttribute("Height")); IDockLayout layout = null; reader.ReadStartElement(); if (reader.LocalName == typeof(DockedWindow).Name) { DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree()); layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null; reader.ReadEndElement(); } else if (reader.LocalName == typeof(GridLayout).Name) { GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree()); layout = gridLayout.Layouts.Count > 0 ? gridLayout : null; reader.ReadEndElement(); } if (layout != null) { if (Children.Count > 0) { RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Add(NewGridSplitter(Orientation)); } RowDefinitions.Add(NewRowDefinition(new GridLength(height, GridUnitType.Star), m_minGridSize.Height)); m_children.Add(layout); Children.Add((FrameworkElement)layout); } } while (reader.ReadToNextSibling("Row")); } break; } for (int i = 0; i < Children.Count; i++) { Grid.SetColumn(Children[i], Orientation == Orientation.Horizontal ? i : 0); Grid.SetRow(Children[i], Orientation == Orientation.Vertical ? i : 0); } reader.ReadEndElement(); } }
public void Dock(IDockContent nextTo, IDockContent newContent, DockTo dockTo) { IDockLayout targetChild = null; if (nextTo != null) { foreach (IDockLayout child in m_children) { if (child.HasChild(nextTo)) { targetChild = child; break; } } } if (targetChild == null) { foreach (IDockLayout child in m_children) { if (child.HasDescendant(nextTo)) { child.Dock(nextTo, newContent, dockTo); // child was docked, nothing else is necessary return; } } } if (dockTo == DockTo.Center && m_children.Count == 1) { m_children[0].Dock(null, newContent, dockTo); } else if (m_children.Count < 2) { if (dockTo == DockTo.Center) { dockTo = DockTo.Right; } if (dockTo == DockTo.Top || dockTo == DockTo.Bottom) { m_orientation = Orientation.Vertical; } else { m_orientation = Orientation.Horizontal; } DockedWindow newChild = new DockedWindow(Root, newContent); if (Children.Count == 0) { AddFirstChild(newChild); } else { if (targetChild == null) { if (dockTo == DockTo.Top || dockTo == DockTo.Left) { targetChild = m_children[0]; } else { targetChild = m_children[m_children.Count - 1]; } } FrameworkElement control = (FrameworkElement)targetChild; int index = m_children.IndexOf(targetChild); if (dockTo == DockTo.Left || dockTo == DockTo.Right) { GridSplitter splitter = NewGridSplitter(Orientation.Horizontal); int column = (int)control.GetValue(Grid.ColumnProperty); ColumnDefinition oldColumn = ColumnDefinitions[index * 2]; ContentSettings contentSettings = (newContent is TabLayout) ? ((TabLayout)newContent).Children[0].Settings : ((DockContent)newContent).Settings; double totalWidth = ((FrameworkElement)targetChild).ActualWidth; double width = Math.Max(Math.Min(contentSettings.Size.Width, (totalWidth - splitter.Width) / 2), (totalWidth - splitter.Width) / 5); double ratioNew = width / totalWidth; double ratioOld = (totalWidth - width - splitter.Width) / totalWidth; if (dockTo == DockTo.Left) { ColumnDefinition leftColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioNew, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinition rightColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioOld, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinitions[index * 2] = leftColumn; ColumnDefinitions.Insert(index * 2 + 1, rightColumn); ColumnDefinitions.Insert(index * 2 + 1, NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index, newChild); Children.Insert(index * 2, splitter); Children.Insert(index * 2, newChild); } else { ColumnDefinition leftColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioOld, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinition rightColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioNew, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinitions[index * 2] = leftColumn; ColumnDefinitions.Insert(index * 2 + 1, rightColumn); ColumnDefinitions.Insert(index * 2 + 1, NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index + 1, newChild); Children.Insert(index * 2 + 1, newChild); Children.Insert(index * 2 + 1, splitter); } for (int i = index * 2; i < Children.Count; i++) { Grid.SetColumn(Children[i], i); } } else { GridSplitter splitter = NewGridSplitter(Orientation.Vertical); int row = (int)control.GetValue(Grid.RowProperty); RowDefinition oldRow = RowDefinitions[index * 2]; ContentSettings contentSettings = (newContent is TabLayout) ? ((TabLayout)newContent).Children[0].Settings : ((DockContent)newContent).Settings; double totalHeight = ((FrameworkElement)targetChild).ActualHeight; double height = Math.Max(Math.Min(contentSettings.Size.Height, (totalHeight - splitter.Height) / 2), (totalHeight - splitter.Height) / 5); double ratioNew = height / totalHeight; double ratioOld = (totalHeight - height - splitter.Height) / totalHeight; if (dockTo == DockTo.Top) { RowDefinition topRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioNew, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinition bottomRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioOld, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinitions[index * 2] = topRow; RowDefinitions.Insert(index * 2 + 1, bottomRow); RowDefinitions.Insert(index * 2 + 1, NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index, newChild); Children.Insert(index * 2, splitter); Children.Insert(index * 2, newChild); } else { RowDefinition topRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioOld, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinition bottomRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioNew, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinitions[index * 2] = topRow; RowDefinitions.Insert(index * 2 + 1, bottomRow); RowDefinitions.Insert(index * 2 + 1, NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index + 1, newChild); Children.Insert(index * 2 + 1, newChild); Children.Insert(index * 2 + 1, splitter); } for (int i = index * 2; i < Children.Count; i++) { Grid.SetRow(Children[i], i); } } } } else if (dockTo == DockTo.Left || dockTo == DockTo.Right || dockTo == DockTo.Top || dockTo == DockTo.Bottom) { DockedWindow dockedWindow = (DockedWindow)targetChild; int index = m_children.IndexOf(targetChild); GridLayout gridLayout = new GridLayout(Root); gridLayout.SetValue(Grid.ColumnProperty, dockedWindow.GetValue(Grid.ColumnProperty)); gridLayout.SetValue(Grid.RowProperty, dockedWindow.GetValue(Grid.RowProperty)); Children.Remove(dockedWindow); IDockContent content = dockedWindow.DockedContent; dockedWindow.Undock(content); m_children[index] = gridLayout; Children.Insert(index * 2, gridLayout); gridLayout.Dock(null, content, DockTo.Center); UpdateLayout(); gridLayout.Dock(content, newContent, dockTo); } else if (targetChild != null) { targetChild.Dock(nextTo, newContent, dockTo); } }
public void ReadXml(System.Xml.XmlReader reader) { if (reader.ReadToFollowing(this.GetType().Name)) { String s = reader.GetAttribute(Orientation.GetType().Name); m_orientation = (Orientation)(Enum.Parse(Orientation.GetType(), s)); switch (m_orientation) { case Orientation.Horizontal: if (reader.ReadToDescendant("Column")) { RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Height)); do { double width = double.Parse(reader.GetAttribute("Width")); IDockLayout layout = null; reader.ReadStartElement(); if (reader.LocalName == typeof(DockedWindow).Name) { DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree()); layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null; reader.ReadEndElement(); } else if (reader.LocalName == typeof(GridLayout).Name) { GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree()); layout = gridLayout.Layouts.Count > 0 ? gridLayout : null; reader.ReadEndElement(); } if (layout != null) { if (Children.Count > 0) { ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Add(NewGridSplitter(Orientation)); } ColumnDefinitions.Add(NewColumnDefinition(new GridLength(width, GridUnitType.Star), m_minGridSize.Width)); m_children.Add(layout); Children.Add((FrameworkElement)layout); } } while (reader.ReadToNextSibling("Column")); } break; case Orientation.Vertical: if (reader.ReadToDescendant("Row")) { ColumnDefinitions.Add(NewColumnDefinition(new GridLength(1, GridUnitType.Star), m_minGridSize.Width)); do { double height = double.Parse(reader.GetAttribute("Height")); IDockLayout layout = null; reader.ReadStartElement(); if (reader.LocalName == typeof(DockedWindow).Name) { DockedWindow dockedWindow = new DockedWindow(Root, reader.ReadSubtree()); layout = dockedWindow.DockedContent.Children.Count != 0 ? dockedWindow : null; reader.ReadEndElement(); } else if (reader.LocalName == typeof(GridLayout).Name) { GridLayout gridLayout = new GridLayout(Root, reader.ReadSubtree()); layout = gridLayout.Layouts.Count > 0 ? gridLayout : null; reader.ReadEndElement(); } if (layout != null) { if (Children.Count > 0) { RowDefinitions.Add(NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); Children.Add(NewGridSplitter(Orientation)); } RowDefinitions.Add(NewRowDefinition(new GridLength(height, GridUnitType.Star), m_minGridSize.Height)); m_children.Add(layout); Children.Add((FrameworkElement)layout); } } while (reader.ReadToNextSibling("Row")); } break; } for(int i = 0; i < Children.Count; i++) { Grid.SetColumn(Children[i], Orientation == Orientation.Horizontal ? i : 0); Grid.SetRow(Children[i], Orientation == Orientation.Vertical ? i : 0); } reader.ReadEndElement(); } }
public void Dock(IDockContent nextTo, IDockContent newContent, DockTo dockTo) { IDockLayout targetChild = null; if (nextTo != null) { foreach (IDockLayout child in m_children) { if (child.HasChild(nextTo)) { targetChild = child; break; } } } if (targetChild == null) { foreach (IDockLayout child in m_children) { if (child.HasDescendant(nextTo)) { child.Dock(nextTo, newContent, dockTo); // child was docked, nothing else is necessary return; } } } if (dockTo == DockTo.Center && m_children.Count == 1) { m_children[0].Dock(null, newContent, dockTo); } else if (m_children.Count < 2) { if (dockTo == DockTo.Center) { dockTo = DockTo.Right; } if (dockTo == DockTo.Top || dockTo == DockTo.Bottom) { m_orientation = Orientation.Vertical; } else { m_orientation = Orientation.Horizontal; } DockedWindow newChild = new DockedWindow(Root, newContent); if (Children.Count == 0) { AddFirstChild(newChild); } else { if (targetChild == null) { if (dockTo == DockTo.Top || dockTo == DockTo.Left) { targetChild = m_children[0]; } else { targetChild = m_children[m_children.Count - 1]; } } FrameworkElement control = (FrameworkElement)targetChild; int index = m_children.IndexOf(targetChild); if (dockTo == DockTo.Left || dockTo == DockTo.Right) { GridSplitter splitter = NewGridSplitter(Orientation.Horizontal); int column = (int)control.GetValue(Grid.ColumnProperty); ColumnDefinition oldColumn = ColumnDefinitions[index * 2]; ContentSettings contentSettings = (newContent is TabLayout) ? ((TabLayout)newContent).Children[0].Settings : ((DockContent)newContent).Settings; double totalWidth = ((FrameworkElement)targetChild).ActualWidth; double width = Math.Max(Math.Min(contentSettings.Size.Width, (totalWidth - splitter.Width) / 2), (totalWidth - splitter.Width) / 5); double ratioNew = width / totalWidth; double ratioOld = (totalWidth - width - splitter.Width) / totalWidth; if (dockTo == DockTo.Left) { ColumnDefinition leftColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioNew, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinition rightColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioOld, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinitions[index * 2] = leftColumn; ColumnDefinitions.Insert(index * 2 + 1, rightColumn); ColumnDefinitions.Insert(index * 2 + 1, NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index, newChild); Children.Insert(index * 2, splitter); Children.Insert(index * 2, newChild); } else { ColumnDefinition leftColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioOld, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinition rightColumn = NewColumnDefinition(new GridLength(oldColumn.Width.Value * ratioNew, oldColumn.Width.GridUnitType), m_minGridSize.Width); ColumnDefinitions[index * 2] = leftColumn; ColumnDefinitions.Insert(index * 2 + 1, rightColumn); ColumnDefinitions.Insert(index * 2 + 1, NewColumnDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index + 1, newChild); Children.Insert(index * 2 + 1, newChild); Children.Insert(index * 2 + 1, splitter); } for (int i = index * 2; i < Children.Count; i++) { Grid.SetColumn(Children[i], i); } } else { GridSplitter splitter = NewGridSplitter(Orientation.Vertical); int row = (int)control.GetValue(Grid.RowProperty); RowDefinition oldRow = RowDefinitions[index * 2]; ContentSettings contentSettings = (newContent is TabLayout) ? ((TabLayout)newContent).Children[0].Settings : ((DockContent)newContent).Settings; double totalHeight = ((FrameworkElement)targetChild).ActualHeight; double height = Math.Max(Math.Min(contentSettings.Size.Height, (totalHeight - splitter.Height) / 2), (totalHeight - splitter.Height) / 5); double ratioNew = height / totalHeight; double ratioOld = (totalHeight - height - splitter.Height) / totalHeight; if (dockTo == DockTo.Top) { RowDefinition topRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioNew, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinition bottomRow = NewRowDefinition(new GridLength(oldRow.Height.Value *ratioOld, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinitions[index * 2] = topRow; RowDefinitions.Insert(index * 2 + 1, bottomRow); RowDefinitions.Insert(index * 2 + 1, NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index, newChild); Children.Insert(index * 2, splitter); Children.Insert(index * 2, newChild); } else { RowDefinition topRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioOld, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinition bottomRow = NewRowDefinition(new GridLength(oldRow.Height.Value * ratioNew, oldRow.Height.GridUnitType), m_minGridSize.Height); RowDefinitions[index * 2] = topRow; RowDefinitions.Insert(index * 2 + 1, bottomRow); RowDefinitions.Insert(index * 2 + 1, NewRowDefinition(new GridLength(1, GridUnitType.Auto), 0)); m_children.Insert(index + 1, newChild); Children.Insert(index * 2 + 1, newChild); Children.Insert(index * 2 + 1, splitter); } for (int i = index * 2; i < Children.Count; i++) { Grid.SetRow(Children[i], i); } } } } else if (dockTo == DockTo.Left || dockTo == DockTo.Right || dockTo == DockTo.Top || dockTo == DockTo.Bottom) { DockedWindow dockedWindow = (DockedWindow)targetChild; int index = m_children.IndexOf(targetChild); GridLayout gridLayout = new GridLayout(Root); gridLayout.SetValue(Grid.ColumnProperty, dockedWindow.GetValue(Grid.ColumnProperty)); gridLayout.SetValue(Grid.RowProperty, dockedWindow.GetValue(Grid.RowProperty)); Children.Remove(dockedWindow); IDockContent content = dockedWindow.DockedContent; dockedWindow.Undock(content); m_children[index] = gridLayout; Children.Insert(index * 2, gridLayout); gridLayout.Dock(null, content, DockTo.Center); UpdateLayout(); gridLayout.Dock(content, newContent, dockTo); } else if (targetChild != null) { targetChild.Dock(nextTo, newContent, dockTo); } }