Browse Source

DropDown -> ComboBox.

Renamed `DropDown` to `ComboBox` to fit in with WPF/UWP.
pull/2393/head
Steven Kirk 7 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 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) =>
{
switch (themes.SelectedIndex)

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

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

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

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

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

@ -18,7 +18,7 @@ namespace Avalonia.Controls
/// <summary>
/// A drop-down list control.
/// </summary>
public class DropDown : SelectingItemsControl
public class ComboBox : SelectingItemsControl
{
/// <summary>
/// The default value for the <see cref="ItemsControl.ItemsPanel"/> property.
@ -29,8 +29,8 @@ namespace Avalonia.Controls
/// <summary>
/// Defines the <see cref="IsDropDownOpen"/> property.
/// </summary>
public static readonly DirectProperty<DropDown, bool> IsDropDownOpenProperty =
AvaloniaProperty.RegisterDirect<DropDown, bool>(
public static readonly DirectProperty<ComboBox, bool> IsDropDownOpenProperty =
AvaloniaProperty.RegisterDirect<ComboBox, bool>(
nameof(IsDropDownOpen),
o => o.IsDropDownOpen,
(o, v) => o.IsDropDownOpen = v);
@ -39,19 +39,19 @@ namespace Avalonia.Controls
/// Defines the <see cref="MaxDropDownHeight"/> property.
/// </summary>
public static readonly StyledProperty<double> MaxDropDownHeightProperty =
AvaloniaProperty.Register<DropDown, double>(nameof(MaxDropDownHeight), 200);
AvaloniaProperty.Register<ComboBox, double>(nameof(MaxDropDownHeight), 200);
/// <summary>
/// Defines the <see cref="SelectionBoxItem"/> property.
/// </summary>
public static readonly DirectProperty<DropDown, object> SelectionBoxItemProperty =
AvaloniaProperty.RegisterDirect<DropDown, object>(nameof(SelectionBoxItem), o => o.SelectionBoxItem);
public static readonly DirectProperty<ComboBox, object> SelectionBoxItemProperty =
AvaloniaProperty.RegisterDirect<ComboBox, object>(nameof(SelectionBoxItem), o => o.SelectionBoxItem);
/// <summary>
/// Defines the <see cref="VirtualizationMode"/> property.
/// </summary>
public static readonly StyledProperty<ItemVirtualizationMode> VirtualizationModeProperty =
ItemsPresenter.VirtualizationModeProperty.AddOwner<DropDown>();
ItemsPresenter.VirtualizationModeProperty.AddOwner<ComboBox>();
private bool _isDropDownOpen;
private Popup _popup;
@ -59,14 +59,14 @@ namespace Avalonia.Controls
private IDisposable _subscriptionsOnOpen;
/// <summary>
/// Initializes static members of the <see cref="DropDown"/> class.
/// Initializes static members of the <see cref="ComboBox"/> class.
/// </summary>
static DropDown()
static ComboBox()
{
ItemsPanelProperty.OverrideDefaultValue<DropDown>(DefaultPanel);
FocusableProperty.OverrideDefaultValue<DropDown>(true);
SelectedItemProperty.Changed.AddClassHandler<DropDown>(x => x.SelectedItemChanged);
KeyDownEvent.AddClassHandler<DropDown>(x => x.OnKeyDown, Interactivity.RoutingStrategies.Tunnel);
ItemsPanelProperty.OverrideDefaultValue<ComboBox>(DefaultPanel);
FocusableProperty.OverrideDefaultValue<ComboBox>(true);
SelectedItemProperty.Changed.AddClassHandler<ComboBox>(x => x.SelectedItemChanged);
KeyDownEvent.AddClassHandler<ComboBox>(x => x.OnKeyDown, Interactivity.RoutingStrategies.Tunnel);
}
/// <summary>
@ -108,10 +108,10 @@ namespace Avalonia.Controls
/// <inheritdoc/>
protected override IItemContainerGenerator CreateItemContainerGenerator()
{
return new ItemContainerGenerator<DropDownItem>(
return new ItemContainerGenerator<ComboBoxItem>(
this,
DropDownItem.ContentProperty,
DropDownItem.ContentTemplateProperty);
ComboBoxItem.ContentProperty,
ComboBoxItem.ContentTemplateProperty);
}
/// <inheritdoc/>
@ -236,7 +236,7 @@ namespace Avalonia.Controls
base.OnTemplateApplied(e);
}
internal void ItemFocused(DropDownItem dropDownItem)
internal void ItemFocused(ComboBoxItem dropDownItem)
{
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
{
/// <summary>
/// A selectable item in a <see cref="DropDown"/>.
/// A selectable item in a <see cref="ComboBox"/>.
/// </summary>
public class DropDownItem : ListBoxItem
public class ComboBoxItem : ListBoxItem
{
public DropDownItem()
public ComboBoxItem()
{
this.GetObservable(DropDownItem.IsFocusedProperty).Where(focused => focused)
.Subscribe(_ => (Parent as DropDown)?.ItemFocused(this));
this.GetObservable(ComboBoxItem.IsFocusedProperty).Where(focused => focused)
.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">
<Style Selector="DropDown">
<Style Selector="ComboBox">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}"/>
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}"/>
<Setter Property="Padding" Value="4"/>
@ -57,7 +57,7 @@
</ControlTemplate>
</Setter>
</Style>
<Style Selector="DropDown:pointerover /template/ Border#border">
<Style Selector="ComboBox:pointerover /template/ Border#border">
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderHighBrush}"/>
</Style>
</Styles>

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

@ -1,5 +1,5 @@
<Styles xmlns="https://github.com/avaloniaui">
<Style Selector="DropDownItem">
<Style Selector="ComboBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
@ -19,23 +19,23 @@
</Setter>
</Style>
<Style Selector="DropDownItem:pointerover /template/ ContentPresenter">
<Style Selector="ComboBoxItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeControlHighlightMidBrush}"/>
</Style>
<Style Selector="DropDownItem:selected /template/ ContentPresenter">
<Style Selector="ComboBoxItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush4}"/>
</Style>
<Style Selector="DropDownItem:selected:focus /template/ ContentPresenter">
<Style Selector="ComboBoxItem:selected:focus /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
<Style Selector="DropDownItem:selected:pointerover /template/ ContentPresenter">
<Style Selector="ComboBoxItem:selected:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush3}"/>
</Style>
<Style Selector="DropDownItem:selected:focus:pointerover /template/ ContentPresenter">
<Style Selector="ComboBoxItem:selected:focus:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
</Style>
</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.Carousel.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.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.ItemsControl.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]
public void Clicking_On_Control_Toggles_IsDropDownOpen()
{
var target = new DropDown
var target = new ComboBox
{
Items = new[] { "Foo", "Bar" },
};
@ -42,13 +42,13 @@ namespace Avalonia.Controls.UnitTests
public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control()
{
var items = new[] { new Canvas() };
var target = new DropDown
var target = new ComboBox
{
Items = items,
SelectedIndex = 0,
};
var rectangle = target.GetValue(DropDown.SelectionBoxItemProperty) as Rectangle;
var rectangle = target.GetValue(ComboBox.SelectionBoxItemProperty) as Rectangle;
Assert.NotNull(rectangle);
var brush = rectangle.Fill as VisualBrush;
@ -59,7 +59,7 @@ namespace Avalonia.Controls.UnitTests
[Fact]
public void SelectionBoxItem_Rectangle_Is_Removed_From_Logical_Tree()
{
var target = new DropDown
var target = new ComboBox
{
Items = new[] { new Canvas() },
SelectedIndex = 0,
@ -70,7 +70,7 @@ namespace Avalonia.Controls.UnitTests
target.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)rectangle).IsAttachedToLogicalTree);
@ -84,7 +84,7 @@ namespace Avalonia.Controls.UnitTests
private FuncControlTemplate GetTemplate()
{
return new FuncControlTemplate<DropDown>(parent =>
return new FuncControlTemplate<ComboBox>(parent =>
{
return new Panel
{
@ -93,7 +93,7 @@ namespace Avalonia.Controls.UnitTests
{
new ContentControl
{
[!ContentControl.ContentProperty] = parent[!DropDown.SelectionBoxItemProperty],
[!ContentControl.ContentProperty] = parent[!ComboBox.SelectionBoxItemProperty],
},
new ToggleButton
{
@ -105,7 +105,7 @@ namespace Avalonia.Controls.UnitTests
Child = new ItemsPresenter
{
Name = "PART_ItemsPresenter",
[!ItemsPresenter.ItemsProperty] = parent[!DropDown.ItemsProperty],
[!ItemsPresenter.ItemsProperty] = parent[!ComboBox.ItemsProperty],
}
}
}

Loading…
Cancel
Save