LayoutElement.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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;
  15. using System.ComponentModel;
  16. using System.Xml.Serialization;
  17. namespace Xceed.Wpf.AvalonDock.Layout
  18. {
  19. [Serializable]
  20. public abstract class LayoutElement : DependencyObject, ILayoutElement
  21. {
  22. internal LayoutElement()
  23. { }
  24. #region Parent
  25. [NonSerialized]
  26. private ILayoutContainer _parent = null;
  27. [NonSerialized]
  28. private ILayoutRoot _root = null;
  29. [XmlIgnore]
  30. public ILayoutContainer Parent
  31. {
  32. get { return _parent; }
  33. set
  34. {
  35. if (_parent != value)
  36. {
  37. ILayoutContainer oldValue = _parent;
  38. ILayoutRoot oldRoot = _root;
  39. RaisePropertyChanging("Parent");
  40. OnParentChanging(oldValue, value);
  41. _parent = value;
  42. OnParentChanged(oldValue, value);
  43. _root = Root;
  44. if (oldRoot != _root)
  45. OnRootChanged(oldRoot, _root);
  46. RaisePropertyChanged("Parent");
  47. var root = Root as LayoutRoot;
  48. if (root != null)
  49. root.FireLayoutUpdated();
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// Provides derived classes an opportunity to handle execute code before to the Parent property changes.
  55. /// </summary>
  56. protected virtual void OnParentChanging(ILayoutContainer oldValue, ILayoutContainer newValue)
  57. {
  58. }
  59. /// <summary>
  60. /// Provides derived classes an opportunity to handle changes to the Parent property.
  61. /// </summary>
  62. protected virtual void OnParentChanged(ILayoutContainer oldValue, ILayoutContainer newValue)
  63. {
  64. }
  65. protected virtual void OnRootChanged(ILayoutRoot oldRoot, ILayoutRoot newRoot)
  66. {
  67. if (oldRoot != null)
  68. ((LayoutRoot)oldRoot).OnLayoutElementRemoved(this);
  69. if (newRoot != null)
  70. ((LayoutRoot)newRoot).OnLayoutElementAdded(this);
  71. }
  72. #endregion
  73. [field: NonSerialized]
  74. [field: XmlIgnore]
  75. public event PropertyChangedEventHandler PropertyChanged;
  76. protected virtual void RaisePropertyChanged(string propertyName)
  77. {
  78. if (PropertyChanged != null)
  79. PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
  80. }
  81. [field: NonSerialized]
  82. [field: XmlIgnore]
  83. public event PropertyChangingEventHandler PropertyChanging;
  84. protected virtual void RaisePropertyChanging(string propertyName)
  85. {
  86. if (PropertyChanging != null)
  87. PropertyChanging(this, new System.ComponentModel.PropertyChangingEventArgs(propertyName));
  88. }
  89. public ILayoutRoot Root
  90. {
  91. get
  92. {
  93. var parent = Parent;
  94. while (parent != null && (!(parent is ILayoutRoot)))
  95. {
  96. parent = parent.Parent;
  97. }
  98. return parent as ILayoutRoot;
  99. }
  100. }
  101. #if TRACE
  102. public virtual void ConsoleDump(int tab)
  103. {
  104. System.Diagnostics.Trace.Write( new String( ' ', tab * 4 ) );
  105. System.Diagnostics.Trace.WriteLine( this.ToString() );
  106. }
  107. #endif
  108. }
  109. }