feat: init

This commit is contained in:
rabbitism
2024-03-22 22:02:00 +08:00
parent eb1eda582f
commit d271623a66
3 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme TargetType="u:MultiComboBox" x:Key="{x:Type u:MultiComboBox}">
<Setter Property="Focusable" Value="True"></Setter>
</ControlTheme>
<ControlTheme TargetType="u:MultiComboBoxItem" x:Key="{x:Type u:MultiComboBoxItem}">
<Setter Property="Focusable" Value="True"></Setter>
</ControlTheme>
</ResourceDictionary>

View File

@@ -0,0 +1,47 @@
using System.Collections.ObjectModel;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
namespace Ursa.Controls;
public class MultiComboBox: SelectingItemsControl
{
private ComboBox _box;
private static ITemplate<Panel?> _defaultPanel = new FuncTemplate<Panel?>(() => new VirtualizingStackPanel());
public static readonly StyledProperty<bool> IsDropDownOpenProperty =
ComboBox.IsDropDownOpenProperty.AddOwner<MultiComboBox>();
public bool IsDropDownOpen
{
get => GetValue(IsDropDownOpenProperty);
set => SetValue(IsDropDownOpenProperty, value);
}
static MultiComboBox()
{
FocusableProperty.OverrideDefaultValue<MultiComboBox>(true);
ItemsPanelProperty.OverrideDefaultValue<MultiComboBox>(_defaultPanel);
}
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
return NeedsContainer<MultiComboBoxItem>(item, out recycleKey);
}
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
{
return new MultiComboBoxItem();
}
internal void ItemFocused(MultiComboBoxItem dropDownItem)
{
if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid)
{
dropDownItem.BringIntoView();
}
}
}

View File

@@ -0,0 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
public class MultiComboBoxItem: ListBoxItem
{
public MultiComboBoxItem()
{
this.GetObservable(IsFocusedProperty).Subscribe(a=> {
if (a)
{
(Parent as MultiComboBox)?.ItemFocused(this);
}
});
}
}