// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Controls { public class TreeViewItem : HeaderedItemsControl { public static readonly PerspexProperty IsExpandedProperty = PerspexProperty.Register("IsExpanded"); public static readonly PerspexProperty IsSelectedProperty = PerspexProperty.Register("IsSelected"); TreeView parent; public TreeViewItem() { this.AddPseudoClass(IsSelectedProperty, ":selected"); AffectsRender(IsSelectedProperty); } public bool IsExpanded { get { return this.GetValue(IsExpandedProperty); } set { this.SetValue(IsExpandedProperty, value); } } public bool IsSelected { get { return this.GetValue(IsSelectedProperty); } set { this.SetValue(IsSelectedProperty, value); } } protected override Control CreateItemControlOverride(object item) { if (this.parent != null) { return this.parent.CreateItemControl(item); } else { return null; } } protected override void OnAttachedToVisualTree() { base.OnAttachedToVisualTree(); this.parent = this.GetVisualAncestor(); } } }