Browse Source

DropDown -> ComboBox.

Renamed `DropDown` to `ComboBox` to fit in with WPF/UWP.
pull/2393/head
Steven Kirk 8 years ago
parent
commit
53b71076d6
  1. 2
      samples/ControlCatalog/MainView.xaml.cs
  2. 8
      samples/ControlCatalog/Pages/CarouselPage.xaml.cs
  3. 2
      samples/ControlCatalog/Pages/DropDownPage.xaml.cs
  4. 34
      src/Avalonia.Controls/ComboBox.cs
  5. 10
      src/Avalonia.Controls/ComboBoxItem.cs
  6. 4
      src/Avalonia.Themes.Default/ComboBox.xaml
  7. 12
      src/Avalonia.Themes.Default/ComboBoxItem.xaml
  8. 4
      src/Avalonia.Themes.Default/DefaultTheme.xaml
  9. 16
      tests/Avalonia.Controls.UnitTests/DropDownTests.cs

2
samples/ControlCatalog/MainView.xaml.cs

@ -30,7 +30,7 @@ namespace ControlCatalog
} }
var light = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default'/>"); var light = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default'/>");
var dark = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default'/>"); var dark = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default'/>");
var themes = this.Find<DropDown>("Themes"); var themes = this.Find<ComboBox>("Themes");
themes.SelectionChanged += (sender, e) => themes.SelectionChanged += (sender, e) =>
{ {
switch (themes.SelectedIndex) switch (themes.SelectedIndex)

8
samples/ControlCatalog/Pages/CarouselPage.xaml.cs

@ -10,8 +10,8 @@ namespace ControlCatalog.Pages
private Carousel _carousel; private Carousel _carousel;
private Button _left; private Button _left;
private Button _right; private Button _right;
private DropDown _transition; private ComboBox _transition;
private DropDown _orientation; private ComboBox _orientation;
public CarouselPage() public CarouselPage()
{ {
@ -28,8 +28,8 @@ namespace ControlCatalog.Pages
_carousel = this.FindControl<Carousel>("carousel"); _carousel = this.FindControl<Carousel>("carousel");
_left = this.FindControl<Button>("left"); _left = this.FindControl<Button>("left");
_right = this.FindControl<Button>("right"); _right = this.FindControl<Button>("right");
_transition = this.FindControl<DropDown>("transition"); _transition = this.FindControl<ComboBox>("transition");
_orientation = this.FindControl<DropDown>("orientation"); _orientation = this.FindControl<ComboBox>("orientation");
} }
private void TransitionChanged(object sender, SelectionChangedEventArgs e) private void TransitionChanged(object sender, SelectionChangedEventArgs e)

2
samples/ControlCatalog/Pages/DropDownPage.xaml.cs

@ -13,7 +13,7 @@ namespace ControlCatalog.Pages
private void InitializeComponent() private void InitializeComponent()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
var fontDropDown = this.Find<DropDown>("fontDropDown"); var fontDropDown = this.Find<ComboBox>("fontDropDown");
fontDropDown.Items = Avalonia.Media.FontFamily.SystemFontFamilies; fontDropDown.Items = Avalonia.Media.FontFamily.SystemFontFamilies;
fontDropDown.SelectedIndex = 0; fontDropDown.SelectedIndex = 0;
} }

34
src/Avalonia.Controls/DropDown.cs → src/Avalonia.Controls/ComboBox.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// A drop-down list control. /// A drop-down list control.
/// </summary> /// </summary>
public class DropDown : SelectingItemsControl public class ComboBox : SelectingItemsControl
{ {
/// <summary> /// <summary>
/// The default value for the <see cref="ItemsControl.ItemsPanel"/> property. /// The default value for the <see cref="ItemsControl.ItemsPanel"/> property.
@ -29,8 +29,8 @@ namespace Avalonia.Controls
/// <summary> /// <summary>
/// Defines the <see cref="IsDropDownOpen"/> property. /// Defines the <see cref="IsDropDownOpen"/> property.
/// </summary> /// </summary>
public static readonly DirectProperty<DropDown, bool> IsDropDownOpenProperty = public static readonly DirectProperty<ComboBox, bool> IsDropDownOpenProperty =
AvaloniaProperty.RegisterDirect<DropDown, bool>( AvaloniaProperty.RegisterDirect<ComboBox, bool>(
nameof(IsDropDownOpen), nameof(IsDropDownOpen),
o => o.IsDropDownOpen, o => o.IsDropDownOpen,
(o, v) => o.IsDropDownOpen = v); (o, v) => o.IsDropDownOpen = v);
@ -39,19 +39,19 @@ namespace Avalonia.Controls
/// Defines the <see cref="MaxDropDownHeight"/> property. /// Defines the <see cref="MaxDropDownHeight"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<double> MaxDropDownHeightProperty = public static readonly StyledProperty<double> MaxDropDownHeightProperty =
AvaloniaProperty.Register<DropDown, double>(nameof(MaxDropDownHeight), 200); AvaloniaProperty.Register<ComboBox, double>(nameof(MaxDropDownHeight), 200);
/// <summary> /// <summary>
/// Defines the <see cref="SelectionBoxItem"/> property. /// Defines the <see cref="SelectionBoxItem"/> property.
/// </summary> /// </summary>
public static readonly DirectProperty<DropDown, object> SelectionBoxItemProperty = public static readonly DirectProperty<ComboBox, object> SelectionBoxItemProperty =
AvaloniaProperty.RegisterDirect<DropDown, object>(nameof(SelectionBoxItem), o => o.SelectionBoxItem); AvaloniaProperty.RegisterDirect<ComboBox, object>(nameof(SelectionBoxItem), o => o.SelectionBoxItem);
/// <summary> /// <summary>
/// Defines the <see cref="VirtualizationMode"/> property. /// Defines the <see cref="VirtualizationMode"/> property.
/// </summary> /// </summary>
public static readonly StyledProperty<ItemVirtualizationMode> VirtualizationModeProperty = public static readonly StyledProperty<ItemVirtualizationMode> VirtualizationModeProperty =
ItemsPresenter.VirtualizationModeProperty.AddOwner<DropDown>(); ItemsPresenter.VirtualizationModeProperty.AddOwner<ComboBox>();
private bool _isDropDownOpen; private bool _isDropDownOpen;
private Popup _popup; private Popup _popup;
@ -59,14 +59,14 @@ namespace Avalonia.Controls
private IDisposable _subscriptionsOnOpen; private IDisposable _subscriptionsOnOpen;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="DropDown"/> class. /// Initializes static members of the <see cref="ComboBox"/> class.
/// </summary> /// </summary>
static DropDown() static ComboBox()
{ {
ItemsPanelProperty.OverrideDefaultValue<DropDown>(DefaultPanel); ItemsPanelProperty.OverrideDefaultValue<ComboBox>(DefaultPanel);
FocusableProperty.OverrideDefaultValue<DropDown>(true); FocusableProperty.OverrideDefaultValue<ComboBox>(true);
SelectedItemProperty.Changed.AddClassHandler<DropDown>(x => x.SelectedItemChanged); SelectedItemProperty.Changed.AddClassHandler<ComboBox>(x => x.SelectedItemChanged);
KeyDownEvent.AddClassHandler<DropDown>(x => x.OnKeyDown, Interactivity.RoutingStrategies.Tunnel); KeyDownEvent.AddClassHandler<ComboBox>(x => x.OnKeyDown, Interactivity.RoutingStrategies.Tunnel);
} }
/// <summary> /// <summary>
@ -108,10 +108,10 @@ namespace Avalonia.Controls
/// <inheritdoc/> /// <inheritdoc/>
protected override IItemContainerGenerator CreateItemContainerGenerator() protected override IItemContainerGenerator CreateItemContainerGenerator()
{ {
return new ItemContainerGenerator<DropDownItem>( return new ItemContainerGenerator<ComboBoxItem>(
this, this,
DropDownItem.ContentProperty, ComboBoxItem.ContentProperty,
DropDownItem.ContentTemplateProperty); ComboBoxItem.ContentTemplateProperty);
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -236,7 +236,7 @@ namespace Avalonia.Controls
base.OnTemplateApplied(e); base.OnTemplateApplied(e);
} }
internal void ItemFocused(DropDownItem dropDownItem) internal void ItemFocused(ComboBoxItem dropDownItem)
{ {
if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid) if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid)
{ {

10
src/Avalonia.Controls/DropDownItem.cs → src/Avalonia.Controls/ComboBoxItem.cs

@ -7,14 +7,14 @@ using System.Reactive.Linq;
namespace Avalonia.Controls namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
/// A selectable item in a <see cref="DropDown"/>. /// A selectable item in a <see cref="ComboBox"/>.
/// </summary> /// </summary>
public class DropDownItem : ListBoxItem public class ComboBoxItem : ListBoxItem
{ {
public DropDownItem() public ComboBoxItem()
{ {
this.GetObservable(DropDownItem.IsFocusedProperty).Where(focused => focused) this.GetObservable(ComboBoxItem.IsFocusedProperty).Where(focused => focused)
.Subscribe(_ => (Parent as DropDown)?.ItemFocused(this)); .Subscribe(_ => (Parent as ComboBox)?.ItemFocused(this));
} }
} }
} }

4
src/Avalonia.Themes.Default/DropDown.xaml → src/Avalonia.Themes.Default/ComboBox.xaml

@ -1,5 +1,5 @@
<Styles xmlns="https://github.com/avaloniaui"> <Styles xmlns="https://github.com/avaloniaui">
<Style Selector="DropDown"> <Style Selector="ComboBox">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/> <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
<Setter Property="Padding" Value="4"/> <Setter Property="Padding" Value="4"/>
@ -57,7 +57,7 @@
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
</Style> </Style>
<Style Selector="DropDown:pointerover /template/ Border#border"> <Style Selector="ComboBox:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style> </Style>
</Styles> </Styles>

12
src/Avalonia.Themes.Default/DropDownItem.xaml → src/Avalonia.Themes.Default/ComboBoxItem.xaml

@ -1,5 +1,5 @@
<Styles xmlns="https://github.com/avaloniaui"> <Styles xmlns="https://github.com/avaloniaui">
<Style Selector="DropDownItem"> <Style Selector="ComboBoxItem">
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="2"/> <Setter Property="Padding" Value="2"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/> <Setter Property="HorizontalAlignment" Value="Stretch"/>
@ -19,23 +19,23 @@
</Setter> </Setter>
</Style> </Style>
<Style Selector="DropDownItem:pointerover /template/ ContentPresenter"> <Style Selector="ComboBoxItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/> <Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/>
</Style> </Style>
<Style Selector="DropDownItem:selected /template/ ContentPresenter"> <Style Selector="ComboBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/> <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
</Style> </Style>
<Style Selector="DropDownItem:selected:focus /template/ ContentPresenter"> <Style Selector="ComboBoxItem:selected:focus /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/> <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style> </Style>
<Style Selector="DropDownItem:selected:pointerover /template/ ContentPresenter"> <Style Selector="ComboBoxItem:selected:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/> <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style> </Style>
<Style Selector="DropDownItem:selected:focus:pointerover /template/ ContentPresenter"> <Style Selector="ComboBoxItem:selected:focus:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
</Style> </Style>
</Styles> </Styles>

4
src/Avalonia.Themes.Default/DefaultTheme.xaml

@ -7,9 +7,9 @@
<StyleInclude Source="resm:Avalonia.Themes.Default.Button.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.Button.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Carousel.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.Carousel.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.CheckBox.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.CheckBox.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ComboBox.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ComboBoxItem.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ContentControl.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.ContentControl.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.DropDown.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.DropDownItem.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.GridSplitter.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.GridSplitter.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ItemsControl.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.ItemsControl.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.ListBox.xaml?assembly=Avalonia.Themes.Default"/> <StyleInclude Source="resm:Avalonia.Themes.Default.ListBox.xaml?assembly=Avalonia.Themes.Default"/>

16
tests/Avalonia.Controls.UnitTests/DropDownTests.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Clicking_On_Control_Toggles_IsDropDownOpen() public void Clicking_On_Control_Toggles_IsDropDownOpen()
{ {
var target = new DropDown var target = new ComboBox
{ {
Items = new[] { "Foo", "Bar" }, Items = new[] { "Foo", "Bar" },
}; };
@ -42,13 +42,13 @@ namespace Avalonia.Controls.UnitTests
public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control() public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control()
{ {
var items = new[] { new Canvas() }; var items = new[] { new Canvas() };
var target = new DropDown var target = new ComboBox
{ {
Items = items, Items = items,
SelectedIndex = 0, SelectedIndex = 0,
}; };
var rectangle = target.GetValue(DropDown.SelectionBoxItemProperty) as Rectangle; var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.NotNull(rectangle); Assert.NotNull(rectangle);
var brush = rectangle.Fill as VisualBrush; var brush = rectangle.Fill as VisualBrush;
@ -59,7 +59,7 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void SelectionBoxItem_Rectangle_Is_Removed_From_Logical_Tree() public void SelectionBoxItem_Rectangle_Is_Removed_From_Logical_Tree()
{ {
var target = new DropDown var target = new ComboBox
{ {
Items = new[] { new Canvas() }, Items = new[] { new Canvas() },
SelectedIndex = 0, SelectedIndex = 0,
@ -70,7 +70,7 @@ namespace Avalonia.Controls.UnitTests
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
var rectangle = target.GetValue(DropDown.SelectionBoxItemProperty) as Rectangle; var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.True(((ILogical)target).IsAttachedToLogicalTree); Assert.True(((ILogical)target).IsAttachedToLogicalTree);
Assert.True(((ILogical)rectangle).IsAttachedToLogicalTree); Assert.True(((ILogical)rectangle).IsAttachedToLogicalTree);
@ -84,7 +84,7 @@ namespace Avalonia.Controls.UnitTests
private FuncControlTemplate GetTemplate() private FuncControlTemplate GetTemplate()
{ {
return new FuncControlTemplate<DropDown>(parent => return new FuncControlTemplate<ComboBox>(parent =>
{ {
return new Panel return new Panel
{ {
@ -93,7 +93,7 @@ namespace Avalonia.Controls.UnitTests
{ {
new ContentControl new ContentControl
{ {
[!ContentControl.ContentProperty] = parent[!DropDown.SelectionBoxItemProperty], [!ContentControl.ContentProperty] = parent[!ComboBox.SelectionBoxItemProperty],
}, },
new ToggleButton new ToggleButton
{ {
@ -105,7 +105,7 @@ namespace Avalonia.Controls.UnitTests
Child = new ItemsPresenter Child = new ItemsPresenter
{ {
Name = "PART_ItemsPresenter", Name = "PART_ItemsPresenter",
[!ItemsPresenter.ItemsProperty] = parent[!DropDown.ItemsProperty], [!ItemsPresenter.ItemsProperty] = parent[!ComboBox.ItemsProperty],
} }
} }
} }

Loading…
Cancel
Save