// -----------------------------------------------------------------------
//
// Copyright 2014 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System;
using Perspex.Controls.Primitives;
using Perspex.Interactivity;
///
/// An selectable item in a .
///
public class ListBoxItem : ContentControl, ISelectable
{
///
/// Defines the property.
///
public static readonly PerspexProperty IsSelectedProperty =
PerspexProperty.Register(nameof(IsSelected));
///
/// Initializes static members of the class.
///
static ListBoxItem()
{
Control.PseudoClass(IsSelectedProperty, ":selected");
IsSelectedProperty.Changed.Subscribe(IsSelectedChanged);
}
///
/// Gets or sets the selection state of the item.
///
public bool IsSelected
{
get { return this.GetValue(IsSelectedProperty); }
set { this.SetValue(IsSelectedProperty, value); }
}
///
/// Called when the property changes on an object.
///
/// The sender.
private static void IsSelectedChanged(PerspexPropertyChangedEventArgs e)
{
var interactive = e.Sender as IInteractive;
if (interactive != null)
{
interactive.RaiseEvent(new RoutedEventArgs(SelectingItemsControl.IsSelectedChangedEvent));
}
}
}
}