using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Collections.Specialized;
using System.Collections;
using System.ComponentModel;
using System.Windows.Controls;
namespace Microsoft.Research.DynamicDataDisplay.Common
{
///
/// 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
/// added or removed.
/// Is intended to be a base class for special layout panels, in which each childr is arranged independently from each other child,
/// e.g. panel with child's position viewport bound to a rectangle in viewport coordinates.
///
public abstract class IndividualArrangePanel : Panel
{
private bool inBatchAdd = false;
///
/// Initializes a new instance of the class.
///
protected IndividualArrangePanel() { }
private UIChildrenCollection children;
///
/// Creates a new .
///
/// The logical parent element of the collection to be created.
///
/// An ordered collection of elements that have the specified logical parent.
///
protected sealed override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)
{
children = new UIChildrenCollection(this, logicalParent);
children.IsAddingMany = inBatchAdd;
return children;
}
public bool InBatchAdd
{
get { return children.IsAddingMany; }
}
public virtual void BeginBatchAdd()
{
if (children == null)
{
inBatchAdd = true;
return;
}
children.IsAddingMany = true;
}
public virtual void EndBatchAdd()
{
children.IsAddingMany = false;
}
///
/// Called when child is added.
///
/// The added child.
protected internal virtual void OnChildAdded(FrameworkElement child) { }
#region Overrides
///
/// Overrides , and returns a child at the specified index from a collection of child elements.
///
/// The zero-based index of the requested child element in the collection.
///
/// The requested child element. This should not return null; if the provided index is out of range, an exception is thrown.
///
protected sealed override Visual GetVisualChild(int index)
{
return Children[index];
}
///
/// Gets the number of visual child elements within this element.
///
///
///
/// The number of visual child elements for this element.
///
protected sealed override int VisualChildrenCount
{
get { return Children.Count; }
}
///
/// Gets an enumerator for logical child elements of this element.
///
///
///
/// An enumerator for logical child elements of this element.
///
protected sealed override IEnumerator LogicalChildren
{
get
{
return Children.GetEnumerator();
}
}
#endregion
}
}