// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Perspex.Collections;
using Perspex.Controls.Generators;
using Perspex.Controls.Presenters;
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
using Perspex.Controls.Utils;
using Perspex.Styling;
namespace Perspex.Controls
{
///
/// Displays a collection of items.
///
public class ItemsControl : TemplatedControl, IReparentingHost
{
///
/// The default value for the property.
///
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Needs to be before or a NullReferenceException is thrown.")]
private static readonly FuncTemplate DefaultPanel =
new FuncTemplate(() => new StackPanel());
///
/// Defines the property.
///
public static readonly PerspexProperty ItemsProperty =
PerspexProperty.Register(nameof(Items));
///
/// Defines the property.
///
public static readonly PerspexProperty> ItemsPanelProperty =
PerspexProperty.Register>(nameof(ItemsPanel), DefaultPanel);
///
/// Defines the property.
///
public static readonly PerspexProperty MemberSelectorProperty =
PerspexProperty.Register(nameof(MemberSelector));
private IItemContainerGenerator _itemContainerGenerator;
///
/// Initializes static members of the class.
///
static ItemsControl()
{
ItemsProperty.Changed.AddClassHandler(x => x.ItemsChanged);
}
///
/// Initializes a new instance of the class.
///
public ItemsControl()
{
Classes.Add(":empty");
Items = new PerspexList