|
|
@ -5,10 +5,12 @@ using Avalonia.Controls.Metadata; |
|
|
using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Shapes; |
|
|
using Avalonia.Controls.Shapes; |
|
|
using Avalonia.Controls.Templates; |
|
|
using Avalonia.Controls.Templates; |
|
|
|
|
|
using Avalonia.Data; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Layout; |
|
|
using Avalonia.Layout; |
|
|
using Avalonia.Media; |
|
|
using Avalonia.Media; |
|
|
|
|
|
using Avalonia.Metadata; |
|
|
using Avalonia.Reactive; |
|
|
using Avalonia.Reactive; |
|
|
using Avalonia.VisualTree; |
|
|
using Avalonia.VisualTree; |
|
|
|
|
|
|
|
|
@ -71,6 +73,23 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty = |
|
|
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty = |
|
|
ContentControl.VerticalContentAlignmentProperty.AddOwner<ComboBox>(); |
|
|
ContentControl.VerticalContentAlignmentProperty.AddOwner<ComboBox>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="SelectionBoxItemTemplate"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<IDataTemplate?> SelectionBoxItemTemplateProperty = |
|
|
|
|
|
AvaloniaProperty.Register<ComboBox, IDataTemplate?>( |
|
|
|
|
|
nameof(SelectionBoxItemTemplate), defaultBindingMode: BindingMode.TwoWay, coerce: CoerceSelectionBoxItemTemplate); |
|
|
|
|
|
|
|
|
|
|
|
private static IDataTemplate? CoerceSelectionBoxItemTemplate(AvaloniaObject obj, IDataTemplate? template) |
|
|
|
|
|
{ |
|
|
|
|
|
if (template is not null) return template; |
|
|
|
|
|
if(obj is ComboBox comboBox && template is null) |
|
|
|
|
|
{ |
|
|
|
|
|
return comboBox.ItemTemplate; |
|
|
|
|
|
} |
|
|
|
|
|
return template; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private Popup? _popup; |
|
|
private Popup? _popup; |
|
|
private object? _selectionBoxItem; |
|
|
private object? _selectionBoxItem; |
|
|
@ -159,6 +178,16 @@ namespace Avalonia.Controls |
|
|
set => SetValue(VerticalContentAlignmentProperty, value); |
|
|
set => SetValue(VerticalContentAlignmentProperty, value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the DataTemplate used to display the selected item. This has a higher priority than <see cref="ItemsControl.ItemTemplate"/> if set.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[InheritDataTypeFromItems(nameof(ItemsSource))] |
|
|
|
|
|
public IDataTemplate? SelectionBoxItemTemplate |
|
|
|
|
|
{ |
|
|
|
|
|
get => GetValue(SelectionBoxItemTemplateProperty); |
|
|
|
|
|
set => SetValue(SelectionBoxItemTemplateProperty, value); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) |
|
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) |
|
|
{ |
|
|
{ |
|
|
base.OnAttachedToVisualTree(e); |
|
|
base.OnAttachedToVisualTree(e); |
|
|
@ -322,7 +351,10 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
PseudoClasses.Set(pcDropdownOpen, change.GetNewValue<bool>()); |
|
|
PseudoClasses.Set(pcDropdownOpen, change.GetNewValue<bool>()); |
|
|
} |
|
|
} |
|
|
|
|
|
else if (change.Property == ItemTemplateProperty) |
|
|
|
|
|
{ |
|
|
|
|
|
CoerceValue(SelectionBoxItemTemplateProperty); |
|
|
|
|
|
} |
|
|
base.OnPropertyChanged(change); |
|
|
base.OnPropertyChanged(change); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -433,7 +465,7 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
if(ItemTemplate is null && DisplayMemberBinding is { } binding) |
|
|
if(ItemTemplate is null && SelectionBoxItemTemplate is null && DisplayMemberBinding is { } binding) |
|
|
{ |
|
|
{ |
|
|
var template = new FuncDataTemplate<object?>((_, _) => |
|
|
var template = new FuncDataTemplate<object?>((_, _) => |
|
|
new TextBlock |
|
|
new TextBlock |
|
|
|