Browse Source

DropDown shouldn't be an IContentControl.

pull/396/head
Steven Kirk 10 years ago
parent
commit
adee104ad9
  1. 54
      src/Perspex.Controls/DropDown.cs
  2. 6
      src/Perspex.Themes.Default/DropDown.paml
  3. 2
      tests/Perspex.Controls.UnitTests/DropDownTests.cs

54
src/Perspex.Controls/DropDown.cs

@ -16,23 +16,20 @@ namespace Perspex.Controls
/// <summary>
/// A drop-down list control.
/// </summary>
public class DropDown : SelectingItemsControl, IContentControl
public class DropDown : SelectingItemsControl
{
public static readonly PerspexProperty<object> ContentProperty =
ContentControl.ContentProperty.AddOwner<DropDown>();
public static readonly PerspexProperty<HorizontalAlignment> HorizontalContentAlignmentProperty =
ContentControl.HorizontalContentAlignmentProperty.AddOwner<DropDown>();
public static readonly PerspexProperty<VerticalAlignment> VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner<DropDown>();
/// <summary>
/// Defines the <see cref="IsDropDownOpen"/> property.
/// </summary>
public static readonly PerspexProperty<bool> IsDropDownOpenProperty =
PerspexProperty.RegisterDirect<DropDown, bool>(
nameof(IsDropDownOpen),
o => o.IsDropDownOpen,
(o, v) => o.IsDropDownOpen = v);
/// <summary>
/// Defines the <see cref="SelectionBoxItem"/> property.
/// </summary>
public static readonly PerspexProperty<object> SelectionBoxItemProperty =
PerspexProperty.RegisterDirect<DropDown, object>("SelectionBoxItem", o => o.SelectionBoxItem);
@ -40,58 +37,47 @@ namespace Perspex.Controls
private Popup _popup;
private object _selectionBoxItem;
/// <summary>
/// Initializes static members of the <see cref="DropDown"/> class.
/// </summary>
static DropDown()
{
FocusableProperty.OverrideDefaultValue<DropDown>(true);
SelectedItemProperty.Changed.AddClassHandler<DropDown>(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); }
}
/// <summary>
/// Gets or sets a value indicating whether the dropdown is currently open.
/// </summary>
public bool IsDropDownOpen
{
get { return _isDropDownOpen; }
set { SetAndRaise(IsDropDownOpenProperty, ref _isDropDownOpen, value); }
}
/// <summary>
/// Gets or sets the item to display as the control's content.
/// </summary>
protected object SelectionBoxItem
{
get { return _selectionBoxItem; }
set { SetAndRaise(SelectionBoxItemProperty, ref _selectionBoxItem, value); }
}
/// <inheritdoc/>
protected override IItemContainerGenerator CreateItemContainerGenerator()
{
return new ItemContainerGenerator<DropDownItem>(this, DropDownItem.ContentProperty);
}
/// <inheritdoc/>
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
base.OnAttachedToLogicalTree(e);
this.UpdateSelectionBoxItem(this.SelectedItem);
}
/// <inheritdoc/>
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
@ -112,6 +98,7 @@ namespace Perspex.Controls
}
}
/// <inheritdoc/>
protected override void OnPointerPressed(PointerPressEventArgs e)
{
if (!IsDropDownOpen && ((IVisual)e.Source).GetVisualRoot() != typeof(PopupRoot))
@ -132,6 +119,7 @@ namespace Perspex.Controls
base.OnPointerPressed(e);
}
/// <inheritdoc/>
protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
{
if (_popup != null)

6
src/Perspex.Themes.Default/DropDown.paml

@ -2,8 +2,6 @@
<Style Selector="DropDown">
<Setter Property="BorderBrush" Value="#ff707070"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="Template">
<ControlTemplate>
@ -13,8 +11,8 @@
<Grid ColumnDefinitions="*,Auto">
<ContentPresenter Content="{TemplateBinding SelectionBoxItem}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<ToggleButton Name="toggle"
BorderThickness="0"
Background="Transparent"

2
tests/Perspex.Controls.UnitTests/DropDownTests.cs

@ -40,7 +40,7 @@ namespace Perspex.Controls.UnitTests
new ContentControl
{
Name = "contentControl",
[~ContentPresenter.ContentProperty] = parent[~DropDown.ContentProperty],
[~ContentPresenter.ContentProperty] = parent[~DropDown.SelectionBoxItemProperty],
},
new ToggleButton
{

Loading…
Cancel
Save