PageRenderTime 47ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Common/IndividualArrangePanel.cs

#
C# | 114 lines | 60 code | 13 blank | 41 comment | 2 complexity | 3f02cd8104f92168e28ab3848b92c74c MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Media;
  7. using System.Collections.Specialized;
  8. using System.Collections;
  9. using System.ComponentModel;
  10. using System.Windows.Controls;
  11. namespace Microsoft.Research.DynamicDataDisplay.Common
  12. {
  13. /// <summary>
  14. /// Represents a custom Panel, which performs Arrange of its children independently, and does not remeasure or rearrange itself or all children when one child is
  15. /// added or removed.
  16. /// Is intended to be a base class for special layout panels, in which each childr is arranged independently from each other child,
  17. /// e.g. panel with child's position viewport bound to a rectangle in viewport coordinates.
  18. /// </summary>
  19. public abstract class IndividualArrangePanel : Panel
  20. {
  21. private bool inBatchAdd = false;
  22. /// <summary>
  23. /// Initializes a new instance of the <see cref="IndependentArrangePanel"/> class.
  24. /// </summary>
  25. protected IndividualArrangePanel() { }
  26. private UIChildrenCollection children;
  27. /// <summary>
  28. /// Creates a new <see cref="T:System.Windows.Controls.UIElementCollection"/>.
  29. /// </summary>
  30. /// <param name="logicalParent">The logical parent element of the collection to be created.</param>
  31. /// <returns>
  32. /// An ordered collection of elements that have the specified logical parent.
  33. /// </returns>
  34. protected sealed override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)
  35. {
  36. children = new UIChildrenCollection(this, logicalParent);
  37. children.IsAddingMany = inBatchAdd;
  38. return children;
  39. }
  40. public bool InBatchAdd
  41. {
  42. get { return children.IsAddingMany; }
  43. }
  44. public virtual void BeginBatchAdd()
  45. {
  46. if (children == null)
  47. {
  48. inBatchAdd = true;
  49. return;
  50. }
  51. children.IsAddingMany = true;
  52. }
  53. public virtual void EndBatchAdd()
  54. {
  55. children.IsAddingMany = false;
  56. }
  57. /// <summary>
  58. /// Called when child is added.
  59. /// </summary>
  60. /// <param name="child">The added child.</param>
  61. protected internal virtual void OnChildAdded(FrameworkElement child) { }
  62. #region Overrides
  63. /// <summary>
  64. /// Overrides <see cref="M:System.Windows.Media.Visual.GetVisualChild(System.Int32)"/>, and returns a child at the specified index from a collection of child elements.
  65. /// </summary>
  66. /// <param name="index">The zero-based index of the requested child element in the collection.</param>
  67. /// <returns>
  68. /// The requested child element. This should not return null; if the provided index is out of range, an exception is thrown.
  69. /// </returns>
  70. protected sealed override Visual GetVisualChild(int index)
  71. {
  72. return Children[index];
  73. }
  74. /// <summary>
  75. /// Gets the number of visual child elements within this element.
  76. /// </summary>
  77. /// <value></value>
  78. /// <returns>
  79. /// The number of visual child elements for this element.
  80. /// </returns>
  81. protected sealed override int VisualChildrenCount
  82. {
  83. get { return Children.Count; }
  84. }
  85. /// <summary>
  86. /// Gets an enumerator for logical child elements of this element.
  87. /// </summary>
  88. /// <value></value>
  89. /// <returns>
  90. /// An enumerator for logical child elements of this element.
  91. /// </returns>
  92. protected sealed override IEnumerator LogicalChildren
  93. {
  94. get
  95. {
  96. return Children.GetEnumerator();
  97. }
  98. }
  99. #endregion
  100. }
  101. }