feat: WIP add a demo.
This commit is contained in:
@@ -3,13 +3,18 @@ using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart( PART_ListBox, typeof(ListBox))]
|
||||
public class MultiComboBox: SelectingItemsControl
|
||||
{
|
||||
public const string PART_ListBox = "PART_ListBox";
|
||||
private ListBox? _listBox;
|
||||
|
||||
private static ITemplate<Panel?> _defaultPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
|
||||
|
||||
public static readonly StyledProperty<bool> IsDropDownOpenProperty =
|
||||
@@ -20,6 +25,15 @@ public class MultiComboBox: SelectingItemsControl
|
||||
get => GetValue(IsDropDownOpenProperty);
|
||||
set => SetValue(IsDropDownOpenProperty, value);
|
||||
}
|
||||
|
||||
public new static readonly StyledProperty<IList?> SelectedItemsProperty = AvaloniaProperty.Register<MultiComboBox, IList?>(
|
||||
nameof(SelectedItems));
|
||||
|
||||
public new IList? SelectedItems
|
||||
{
|
||||
get => GetValue(SelectedItemsProperty);
|
||||
set => SetValue(SelectedItemsProperty, value);
|
||||
}
|
||||
|
||||
static MultiComboBox()
|
||||
{
|
||||
@@ -44,4 +58,22 @@ public class MultiComboBox: SelectingItemsControl
|
||||
dropDownItem.BringIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
_listBox = e.NameScope.Find<ListBox>(PART_ListBox);
|
||||
if (_listBox != null)
|
||||
{
|
||||
_listBox.SelectionChanged += ListBox_SelectionChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender == _listBox)
|
||||
{
|
||||
this.SelectedItems = _listBox.SelectedItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user