feat: add inner contents.
This commit is contained in:
@@ -12,14 +12,18 @@ using Avalonia.Metadata;
|
||||
using Avalonia.VisualTree;
|
||||
using Irihi.Avalonia.Shared.Common;
|
||||
using Irihi.Avalonia.Shared.Contracts;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
using Size = Avalonia.Size;
|
||||
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
[TemplatePart(PartNames.PART_Popup, typeof(Popup))]
|
||||
[PseudoClasses(PC_DropdownOpen)]
|
||||
public class TreeComboBox: ItemsControl, IClearControl, IInnerContentControl, IPopupInnerContent
|
||||
{
|
||||
public const string PC_DropdownOpen = ":dropdownopen";
|
||||
|
||||
private Popup? _popup;
|
||||
|
||||
private static readonly FuncTemplate<Panel?> DefaultPanel =
|
||||
@@ -101,12 +105,49 @@ public class TreeComboBox: ItemsControl, IClearControl, IInnerContentControl, IP
|
||||
get => _selectedItem;
|
||||
set => SetAndRaise(SelectedItemProperty, ref _selectedItem, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> InnerLeftContentProperty = AvaloniaProperty.Register<TreeComboBox, object?>(
|
||||
nameof(InnerLeftContent));
|
||||
|
||||
public object? InnerLeftContent
|
||||
{
|
||||
get => GetValue(InnerLeftContentProperty);
|
||||
set => SetValue(InnerLeftContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> InnerRightContentProperty = AvaloniaProperty.Register<TreeComboBox, object?>(
|
||||
nameof(InnerRightContent));
|
||||
|
||||
public object? InnerRightContent
|
||||
{
|
||||
get => GetValue(InnerRightContentProperty);
|
||||
set => SetValue(InnerRightContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> PopupInnerTopContentProperty = AvaloniaProperty.Register<TreeComboBox, object?>(
|
||||
nameof(PopupInnerTopContent));
|
||||
|
||||
public object? PopupInnerTopContent
|
||||
{
|
||||
get => GetValue(PopupInnerTopContentProperty);
|
||||
set => SetValue(PopupInnerTopContentProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> PopupInnerBottomContentProperty = AvaloniaProperty.Register<TreeComboBox, object?>(
|
||||
nameof(PopupInnerBottomContent));
|
||||
|
||||
public object? PopupInnerBottomContent
|
||||
{
|
||||
get => GetValue(PopupInnerBottomContentProperty);
|
||||
set => SetValue(PopupInnerBottomContentProperty, value);
|
||||
}
|
||||
|
||||
static TreeComboBox()
|
||||
{
|
||||
ItemsPanelProperty.OverrideDefaultValue<TreeComboBox>(DefaultPanel);
|
||||
FocusableProperty.OverrideDefaultValue<TreeComboBox>(true);
|
||||
SelectedItemProperty.Changed.AddClassHandler<TreeComboBox, object?>((box, args) => box.OnSelectedItemChanged(args));
|
||||
IsDropDownOpenProperty.AffectsPseudoClass<TreeComboBox>(PC_DropdownOpen);
|
||||
}
|
||||
|
||||
private void OnSelectedItemChanged(AvaloniaPropertyChangedEventArgs<object?> args)
|
||||
@@ -293,9 +334,4 @@ public class TreeComboBox: ItemsControl, IClearControl, IInnerContentControl, IP
|
||||
{
|
||||
SelectedItem = null;
|
||||
}
|
||||
|
||||
public object? InnerLeftContent { get; set; }
|
||||
public object? InnerRightContent { get; set; }
|
||||
public object? PopupInnerTopContent { get; set; }
|
||||
public object? PopupInnerBottomContent { get; set; }
|
||||
}
|
||||
@@ -6,11 +6,14 @@ namespace Ursa.Converters;
|
||||
|
||||
public class SelectionBoxTemplateConverter: IMultiValueConverter
|
||||
{
|
||||
public static SelectionBoxTemplateConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
var selectedItemTemplate = values.Count > 0 ? values[0] as IDataTemplate : null;
|
||||
if (selectedItemTemplate is not null) return selectedItemTemplate;
|
||||
var itemTemplate = values.Count > 1 ? values[1] as IDataTemplate : null;
|
||||
return itemTemplate;
|
||||
for (int i = 0; i < values.Count; i++)
|
||||
{
|
||||
if (values[i] is IDataTemplate template) return template;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user