LayoutPositionableGroup.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.Globalization;
  16. namespace Xceed.Wpf.AvalonDock.Layout
  17. {
  18. [Serializable]
  19. public abstract class LayoutPositionableGroup<T> : LayoutGroup<T>, ILayoutPositionableElement, ILayoutPositionableElementWithActualSize where T : class, ILayoutElement
  20. {
  21. public LayoutPositionableGroup()
  22. { }
  23. GridLength _dockWidth = new GridLength(1.0, GridUnitType.Star);
  24. public GridLength DockWidth
  25. {
  26. get
  27. {
  28. return _dockWidth;
  29. }
  30. set
  31. {
  32. if (DockWidth != value)
  33. {
  34. RaisePropertyChanging("DockWidth");
  35. _dockWidth = value;
  36. RaisePropertyChanged("DockWidth");
  37. OnDockWidthChanged();
  38. }
  39. }
  40. }
  41. protected virtual void OnDockWidthChanged()
  42. {
  43. }
  44. GridLength _dockHeight = new GridLength(1.0, GridUnitType.Star);
  45. public GridLength DockHeight
  46. {
  47. get
  48. {
  49. return _dockHeight;
  50. }
  51. set
  52. {
  53. if (DockHeight != value)
  54. {
  55. RaisePropertyChanging("DockHeight");
  56. _dockHeight = value;
  57. RaisePropertyChanged("DockHeight");
  58. OnDockHeightChanged();
  59. }
  60. }
  61. }
  62. protected virtual void OnDockHeightChanged()
  63. {
  64. }
  65. #region DockMinWidth
  66. private double _dockMinWidth = 25.0;
  67. public double DockMinWidth
  68. {
  69. get { return _dockMinWidth; }
  70. set
  71. {
  72. if (_dockMinWidth != value)
  73. {
  74. MathHelper.AssertIsPositiveOrZero(value);
  75. RaisePropertyChanging("DockMinWidth");
  76. _dockMinWidth = value;
  77. RaisePropertyChanged("DockMinWidth");
  78. }
  79. }
  80. }
  81. #endregion
  82. #region DockMinHeight
  83. private double _dockMinHeight = 25.0;
  84. public double DockMinHeight
  85. {
  86. get { return _dockMinHeight; }
  87. set
  88. {
  89. if (_dockMinHeight != value)
  90. {
  91. MathHelper.AssertIsPositiveOrZero(value);
  92. RaisePropertyChanging("DockMinHeight");
  93. _dockMinHeight = value;
  94. RaisePropertyChanged("DockMinHeight");
  95. }
  96. }
  97. }
  98. #endregion
  99. #region FloatingWidth
  100. private double _floatingWidth = 0.0;
  101. public double FloatingWidth
  102. {
  103. get { return _floatingWidth; }
  104. set
  105. {
  106. if (_floatingWidth != value)
  107. {
  108. RaisePropertyChanging("FloatingWidth");
  109. _floatingWidth = value;
  110. RaisePropertyChanged("FloatingWidth");
  111. }
  112. }
  113. }
  114. #endregion
  115. #region FloatingHeight
  116. private double _floatingHeight = 0.0;
  117. public double FloatingHeight
  118. {
  119. get { return _floatingHeight; }
  120. set
  121. {
  122. if (_floatingHeight != value)
  123. {
  124. RaisePropertyChanging("FloatingHeight");
  125. _floatingHeight = value;
  126. RaisePropertyChanged("FloatingHeight");
  127. }
  128. }
  129. }
  130. #endregion
  131. #region FloatingLeft
  132. private double _floatingLeft = 0.0;
  133. public double FloatingLeft
  134. {
  135. get { return _floatingLeft; }
  136. set
  137. {
  138. if (_floatingLeft != value)
  139. {
  140. RaisePropertyChanging("FloatingLeft");
  141. _floatingLeft = value;
  142. RaisePropertyChanged("FloatingLeft");
  143. }
  144. }
  145. }
  146. #endregion
  147. #region FloatingTop
  148. private double _floatingTop = 0.0;
  149. public double FloatingTop
  150. {
  151. get { return _floatingTop; }
  152. set
  153. {
  154. if (_floatingTop != value)
  155. {
  156. RaisePropertyChanging("FloatingTop");
  157. _floatingTop = value;
  158. RaisePropertyChanged("FloatingTop");
  159. }
  160. }
  161. }
  162. #endregion
  163. #region IsMaximized
  164. private bool _isMaximized = false;
  165. public bool IsMaximized
  166. {
  167. get { return _isMaximized; }
  168. set
  169. {
  170. if (_isMaximized != value)
  171. {
  172. _isMaximized = value;
  173. RaisePropertyChanged("IsMaximized");
  174. }
  175. }
  176. }
  177. #endregion
  178. [NonSerialized]
  179. double _actualWidth;
  180. double ILayoutPositionableElementWithActualSize.ActualWidth
  181. {
  182. get
  183. {
  184. return _actualWidth;
  185. }
  186. set
  187. {
  188. _actualWidth = value;
  189. }
  190. }
  191. [NonSerialized]
  192. double _actualHeight;
  193. double ILayoutPositionableElementWithActualSize.ActualHeight
  194. {
  195. get
  196. {
  197. return _actualHeight;
  198. }
  199. set
  200. {
  201. _actualHeight = value;
  202. }
  203. }
  204. public override void WriteXml(System.Xml.XmlWriter writer)
  205. {
  206. if (DockWidth.Value != 1.0 || !DockWidth.IsStar)
  207. writer.WriteAttributeString("DockWidth", _gridLengthConverter.ConvertToInvariantString(DockWidth));
  208. if (DockHeight.Value != 1.0 || !DockHeight.IsStar)
  209. writer.WriteAttributeString("DockHeight", _gridLengthConverter.ConvertToInvariantString(DockHeight));
  210. if (DockMinWidth != 25.0)
  211. writer.WriteAttributeString("DocMinWidth", DockMinWidth.ToString(CultureInfo.InvariantCulture));
  212. if (DockMinHeight != 25.0)
  213. writer.WriteAttributeString("DockMinHeight", DockMinHeight.ToString(CultureInfo.InvariantCulture));
  214. if (FloatingWidth != 0.0)
  215. writer.WriteAttributeString("FloatingWidth", FloatingWidth.ToString(CultureInfo.InvariantCulture));
  216. if (FloatingHeight != 0.0)
  217. writer.WriteAttributeString("FloatingHeight", FloatingHeight.ToString(CultureInfo.InvariantCulture));
  218. if (FloatingLeft != 0.0)
  219. writer.WriteAttributeString("FloatingLeft", FloatingLeft.ToString(CultureInfo.InvariantCulture));
  220. if (FloatingTop != 0.0)
  221. writer.WriteAttributeString("FloatingTop", FloatingTop.ToString(CultureInfo.InvariantCulture));
  222. if( IsMaximized )
  223. writer.WriteAttributeString( "IsMaximized", IsMaximized.ToString() );
  224. base.WriteXml(writer);
  225. }
  226. static GridLengthConverter _gridLengthConverter = new GridLengthConverter();
  227. public override void ReadXml(System.Xml.XmlReader reader)
  228. {
  229. if (reader.MoveToAttribute("DockWidth"))
  230. _dockWidth = (GridLength)_gridLengthConverter.ConvertFromInvariantString(reader.Value);
  231. if (reader.MoveToAttribute("DockHeight"))
  232. _dockHeight = (GridLength)_gridLengthConverter.ConvertFromInvariantString(reader.Value);
  233. if (reader.MoveToAttribute("DocMinWidth"))
  234. _dockMinWidth = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  235. if (reader.MoveToAttribute("DocMinHeight"))
  236. _dockMinHeight = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  237. if (reader.MoveToAttribute("FloatingWidth"))
  238. _floatingWidth = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  239. if (reader.MoveToAttribute("FloatingHeight"))
  240. _floatingHeight = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  241. if (reader.MoveToAttribute("FloatingLeft"))
  242. _floatingLeft = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  243. if (reader.MoveToAttribute("FloatingTop"))
  244. _floatingTop = double.Parse(reader.Value, CultureInfo.InvariantCulture);
  245. if( reader.MoveToAttribute( "IsMaximized" ) )
  246. _isMaximized = bool.Parse( reader.Value );
  247. base.ReadXml(reader);
  248. }
  249. }
  250. }