feat: init
This commit is contained in:
12
src/Ursa.Themes.Semi/Controls/MultiComboBox.axaml
Normal file
12
src/Ursa.Themes.Semi/Controls/MultiComboBox.axaml
Normal 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>
|
||||
47
src/Ursa/Controls/ComboBox/MultiComboBox.cs
Normal file
47
src/Ursa/Controls/ComboBox/MultiComboBox.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Ursa/Controls/ComboBox/MultiComboBoxItem.cs
Normal file
18
src/Ursa/Controls/ComboBox/MultiComboBoxItem.cs
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user