From adee104ad9e7ddc55ca5c892070cf5d7de020492 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 16 Jan 2016 15:20:05 +0100 Subject: [PATCH] DropDown shouldn't be an IContentControl. --- src/Perspex.Controls/DropDown.cs | 54 ++++++++----------- src/Perspex.Themes.Default/DropDown.paml | 6 +-- .../DropDownTests.cs | 2 +- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/Perspex.Controls/DropDown.cs b/src/Perspex.Controls/DropDown.cs index 6f69fcaeaf..8742016d9c 100644 --- a/src/Perspex.Controls/DropDown.cs +++ b/src/Perspex.Controls/DropDown.cs @@ -16,23 +16,20 @@ namespace Perspex.Controls /// /// A drop-down list control. /// - public class DropDown : SelectingItemsControl, IContentControl + public class DropDown : SelectingItemsControl { - public static readonly PerspexProperty ContentProperty = - ContentControl.ContentProperty.AddOwner(); - - public static readonly PerspexProperty HorizontalContentAlignmentProperty = - ContentControl.HorizontalContentAlignmentProperty.AddOwner(); - - public static readonly PerspexProperty VerticalContentAlignmentProperty = - ContentControl.VerticalContentAlignmentProperty.AddOwner(); - + /// + /// Defines the property. + /// public static readonly PerspexProperty IsDropDownOpenProperty = PerspexProperty.RegisterDirect( nameof(IsDropDownOpen), o => o.IsDropDownOpen, (o, v) => o.IsDropDownOpen = v); + /// + /// Defines the property. + /// public static readonly PerspexProperty SelectionBoxItemProperty = PerspexProperty.RegisterDirect("SelectionBoxItem", o => o.SelectionBoxItem); @@ -40,58 +37,47 @@ namespace Perspex.Controls private Popup _popup; private object _selectionBoxItem; + /// + /// Initializes static members of the class. + /// static DropDown() { FocusableProperty.OverrideDefaultValue(true); SelectedItemProperty.Changed.AddClassHandler(x => x.SelectedItemChanged); } - public DropDown() - { - Bind(ContentProperty, GetObservable(SelectedItemProperty)); - } - - public object Content - { - get { return GetValue(ContentProperty); } - set { SetValue(ContentProperty, value); } - } - - public HorizontalAlignment HorizontalContentAlignment - { - get { return GetValue(HorizontalContentAlignmentProperty); } - set { SetValue(HorizontalContentAlignmentProperty, value); } - } - - public VerticalAlignment VerticalContentAlignment - { - get { return GetValue(VerticalContentAlignmentProperty); } - set { SetValue(VerticalContentAlignmentProperty, value); } - } - + /// + /// Gets or sets a value indicating whether the dropdown is currently open. + /// public bool IsDropDownOpen { get { return _isDropDownOpen; } set { SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); } } + /// + /// Gets or sets the item to display as the control's content. + /// protected object SelectionBoxItem { get { return _selectionBoxItem; } set { SetAndRaise(SelectionBoxItemProperty, ref _selectionBoxItem, value); } } + /// protected override IItemContainerGenerator CreateItemContainerGenerator() { return new ItemContainerGenerator(this, DropDownItem.ContentProperty); } + /// protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { base.OnAttachedToLogicalTree(e); this.UpdateSelectionBoxItem(this.SelectedItem); } + /// protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); @@ -112,6 +98,7 @@ namespace Perspex.Controls } } + /// protected override void OnPointerPressed(PointerPressEventArgs e) { if (!IsDropDownOpen && ((IVisual)e.Source).GetVisualRoot() != typeof(PopupRoot)) @@ -132,6 +119,7 @@ namespace Perspex.Controls base.OnPointerPressed(e); } + /// protected override void OnTemplateApplied(TemplateAppliedEventArgs e) { if (_popup != null) diff --git a/src/Perspex.Themes.Default/DropDown.paml b/src/Perspex.Themes.Default/DropDown.paml index 2d65df2c29..d1646ac21c 100644 --- a/src/Perspex.Themes.Default/DropDown.paml +++ b/src/Perspex.Themes.Default/DropDown.paml @@ -2,8 +2,6 @@