// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
namespace System.Windows.Controls.DataVisualization.Charting.Primitives
{
///
/// Subclasses ListBox to provide an easy way for a consumer of
/// ListBox to hook into the four standard ListBox *Container*
/// overrides.
///
/// Preview
public class DelegatingListBox : ListBox
{
///
/// Gets or sets a function to call when the
/// IsItemItsOwnContainerOverride method executes.
///
public Func IsItemItsOwnContainer { get; set; }
///
/// Gets or sets a function to call when the
/// GetContainerForItem method executes.
///
public Func GetContainerForItem { get; set; }
///
/// Gets or sets an action to call when the
/// PrepareContainerForItem method executes.
///
public Action PrepareContainerForItem { get; set; }
///
/// Gets or sets an action to call when the
/// ClearContainerForItem method executes.
///
public Action ClearContainerForItem { get; set; }
#if !SILVERLIGHT
///
/// Initializes static members of the DelegatingListBox class.
///
static DelegatingListBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DelegatingListBox), new FrameworkPropertyMetadata(typeof(DelegatingListBox)));
}
#endif
///
/// Initializes a new instance of the DelegatingListBox class.
///
public DelegatingListBox()
{
#if SILVERLIGHT
DefaultStyleKey = typeof(DelegatingListBox);
#endif
}
///
/// Determines if the specified item is (or is eligible to be) its own container.
///
/// The item to check.
/// True if the item is (or is eligible to be) its own container; otherwise, false.
protected override bool IsItemItsOwnContainerOverride(object item)
{
return (null != IsItemItsOwnContainer) ?
IsItemItsOwnContainer(item) :
base.IsItemItsOwnContainerOverride(item);
}
///
/// Creates or identifies the element that is used to display the given item.
///
/// The element that is used to display the given item.
protected override DependencyObject GetContainerForItemOverride()
{
return (null != GetContainerForItem) ?
GetContainerForItem() :
base.GetContainerForItemOverride();
}
///
/// Prepares the specified element to display the specified item.
///
/// The element used to display the specified item.
/// The item to display.
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
if (null != PrepareContainerForItem)
{
PrepareContainerForItem(element, item);
}
}
///
/// Undoes the effects of the PrepareContainerForItemOverride method.
///
/// The container element.
/// The item to display.
protected override void ClearContainerForItemOverride(DependencyObject element, object item)
{
base.ClearContainerForItemOverride(element, item);
if (null != ClearContainerForItem)
{
ClearContainerForItem(element, item);
}
}
}
}