LayoutAnchorablePaneGroup.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*************************************************************************************
  2. Extended WPF Toolkit
  3. Copyright (C) 2007-2013 Xceed Software Inc.
  4. This program is provided to you under the terms of the Microsoft Public
  5. License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
  6. For more features, controls, and fast professional support,
  7. pick up the Plus Edition at http://xceed.com/wpf_toolkit
  8. Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
  9. ***********************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Collections.ObjectModel;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Markup;
  18. namespace Xceed.Wpf.AvalonDock.Layout
  19. {
  20. [ContentProperty("Children")]
  21. [Serializable]
  22. public class LayoutAnchorablePaneGroup : LayoutPositionableGroup<ILayoutAnchorablePane>, ILayoutAnchorablePane, ILayoutOrientableGroup
  23. {
  24. public LayoutAnchorablePaneGroup()
  25. {
  26. }
  27. public LayoutAnchorablePaneGroup(LayoutAnchorablePane firstChild)
  28. {
  29. Children.Add(firstChild);
  30. }
  31. #region Orientation
  32. private Orientation _orientation;
  33. public Orientation Orientation
  34. {
  35. get { return _orientation; }
  36. set
  37. {
  38. if (_orientation != value)
  39. {
  40. RaisePropertyChanging("Orientation");
  41. _orientation = value;
  42. RaisePropertyChanged("Orientation");
  43. }
  44. }
  45. }
  46. #endregion
  47. protected override bool GetVisibility()
  48. {
  49. return Children.Count > 0 && Children.Any(c => c.IsVisible);
  50. }
  51. protected override void OnIsVisibleChanged()
  52. {
  53. UpdateParentVisibility();
  54. base.OnIsVisibleChanged();
  55. }
  56. void UpdateParentVisibility()
  57. {
  58. var parentPane = Parent as ILayoutElementWithVisibility;
  59. if (parentPane != null)
  60. parentPane.ComputeVisibility();
  61. }
  62. protected override void OnDockWidthChanged()
  63. {
  64. if (DockWidth.IsAbsolute && ChildrenCount == 1)
  65. ((ILayoutPositionableElement)Children[0]).DockWidth = DockWidth;
  66. base.OnDockWidthChanged();
  67. }
  68. protected override void OnDockHeightChanged()
  69. {
  70. if (DockHeight.IsAbsolute && ChildrenCount == 1)
  71. ((ILayoutPositionableElement)Children[0]).DockHeight = DockHeight;
  72. base.OnDockHeightChanged();
  73. }
  74. protected override void OnChildrenCollectionChanged()
  75. {
  76. if (DockWidth.IsAbsolute && ChildrenCount == 1)
  77. ((ILayoutPositionableElement)Children[0]).DockWidth = DockWidth;
  78. if (DockHeight.IsAbsolute && ChildrenCount == 1)
  79. ((ILayoutPositionableElement)Children[0]).DockHeight = DockHeight;
  80. base.OnChildrenCollectionChanged();
  81. }
  82. public override void WriteXml(System.Xml.XmlWriter writer)
  83. {
  84. writer.WriteAttributeString("Orientation", Orientation.ToString());
  85. base.WriteXml(writer);
  86. }
  87. public override void ReadXml(System.Xml.XmlReader reader)
  88. {
  89. if (reader.MoveToAttribute("Orientation"))
  90. Orientation = (Orientation)Enum.Parse(typeof(Orientation), reader.Value, true);
  91. base.ReadXml(reader);
  92. }
  93. #if TRACE
  94. public override void ConsoleDump(int tab)
  95. {
  96. System.Diagnostics.Trace.Write( new string( ' ', tab * 4 ) );
  97. System.Diagnostics.Trace.WriteLine( string.Format( "AnchorablePaneGroup({0})", Orientation ) );
  98. foreach (LayoutElement child in Children)
  99. child.ConsoleDump(tab + 1);
  100. }
  101. #endif
  102. }
  103. }