LayoutAnchorableFloatingWindow.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.Windows.Markup;
  15. using System.Diagnostics;
  16. using System.Xml.Serialization;
  17. namespace Xceed.Wpf.AvalonDock.Layout
  18. {
  19. [Serializable]
  20. [ContentProperty("RootPanel")]
  21. public class LayoutAnchorableFloatingWindow : LayoutFloatingWindow, ILayoutElementWithVisibility
  22. {
  23. public LayoutAnchorableFloatingWindow()
  24. {
  25. }
  26. #region RootPanel
  27. private LayoutAnchorablePaneGroup _rootPanel = null;
  28. public LayoutAnchorablePaneGroup RootPanel
  29. {
  30. get { return _rootPanel; }
  31. set
  32. {
  33. if (_rootPanel != value)
  34. {
  35. RaisePropertyChanging("RootPanel");
  36. if (_rootPanel != null)
  37. _rootPanel.ChildrenTreeChanged -= new EventHandler<ChildrenTreeChangedEventArgs>(_rootPanel_ChildrenTreeChanged);
  38. _rootPanel = value;
  39. if (_rootPanel != null)
  40. _rootPanel.Parent = this;
  41. if (_rootPanel != null)
  42. _rootPanel.ChildrenTreeChanged += new EventHandler<ChildrenTreeChangedEventArgs>(_rootPanel_ChildrenTreeChanged);
  43. RaisePropertyChanged("RootPanel");
  44. RaisePropertyChanged("IsSinglePane");
  45. RaisePropertyChanged("SinglePane");
  46. RaisePropertyChanged("Children");
  47. RaisePropertyChanged("ChildrenCount");
  48. ((ILayoutElementWithVisibility)this).ComputeVisibility();
  49. }
  50. }
  51. }
  52. void _rootPanel_ChildrenTreeChanged(object sender, ChildrenTreeChangedEventArgs e)
  53. {
  54. RaisePropertyChanged("IsSinglePane");
  55. RaisePropertyChanged("SinglePane");
  56. }
  57. public bool IsSinglePane
  58. {
  59. get
  60. {
  61. return RootPanel != null && RootPanel.Descendents().OfType<ILayoutAnchorablePane>().Where(p => p.IsVisible).Count() == 1;
  62. }
  63. }
  64. public ILayoutAnchorablePane SinglePane
  65. {
  66. get
  67. {
  68. if (!IsSinglePane)
  69. return null;
  70. var singlePane = RootPanel.Descendents().OfType<LayoutAnchorablePane>().Single(p => p.IsVisible);
  71. singlePane.UpdateIsDirectlyHostedInFloatingWindow();
  72. return singlePane;
  73. }
  74. }
  75. #endregion
  76. public override IEnumerable<ILayoutElement> Children
  77. {
  78. get
  79. {
  80. if (ChildrenCount == 1)
  81. yield return RootPanel;
  82. yield break;
  83. }
  84. }
  85. public override void RemoveChild(ILayoutElement element)
  86. {
  87. Debug.Assert(element == RootPanel && element != null);
  88. RootPanel = null;
  89. }
  90. public override void ReplaceChild(ILayoutElement oldElement, ILayoutElement newElement)
  91. {
  92. Debug.Assert(oldElement == RootPanel && oldElement != null);
  93. RootPanel = newElement as LayoutAnchorablePaneGroup;
  94. }
  95. public override int ChildrenCount
  96. {
  97. get
  98. {
  99. if (RootPanel == null)
  100. return 0;
  101. return 1;
  102. }
  103. }
  104. #region IsVisible
  105. [NonSerialized]
  106. private bool _isVisible = true;
  107. [XmlIgnore]
  108. public bool IsVisible
  109. {
  110. get { return _isVisible; }
  111. private set
  112. {
  113. if (_isVisible != value)
  114. {
  115. RaisePropertyChanging("IsVisible");
  116. _isVisible = value;
  117. RaisePropertyChanged("IsVisible");
  118. if (IsVisibleChanged != null)
  119. IsVisibleChanged(this, EventArgs.Empty);
  120. }
  121. }
  122. }
  123. public event EventHandler IsVisibleChanged;
  124. #endregion
  125. void ILayoutElementWithVisibility.ComputeVisibility()
  126. {
  127. if (RootPanel != null)
  128. IsVisible = RootPanel.IsVisible;
  129. else
  130. IsVisible = false;
  131. }
  132. public override bool IsValid
  133. {
  134. get { return RootPanel != null; }
  135. }
  136. #if TRACE
  137. public override void ConsoleDump(int tab)
  138. {
  139. System.Diagnostics.Trace.Write( new string( ' ', tab * 4 ) );
  140. System.Diagnostics.Trace.WriteLine( "FloatingAnchorableWindow()" );
  141. RootPanel.ConsoleDump(tab + 1);
  142. }
  143. #endif
  144. }
  145. }