feat: improve styling.

This commit is contained in:
rabbitism
2024-04-15 03:35:27 +08:00
parent edf0e387cc
commit 1521b07785
5 changed files with 188 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.LogicalTree;
using Avalonia.OpenGL.Controls;
using Irihi.Avalonia.Shared.Common;
@@ -115,24 +116,31 @@ public class TreeComboBox: SelectingItemsControl
return CreateContainerForItemOverride(item, index, recycleKey);
}
protected override void ContainerForItemPreparedOverride(Control container, object? item, int index)
{
base.ContainerForItemPreparedOverride(container, item, index);
}
internal void ContainerForItemPreparedInternal(Control container, object? item, int index)
{
ContainerForItemPreparedOverride(container, item, index);
}
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
if (e.InitialPressMouseButton == MouseButton.Left)
{
if (_popup is not null && _popup.IsOpen && e.Source is TextBlock v && _popup.IsInsidePopup(v))
if (_popup is not null && _popup.IsOpen && e.Source is Visual v && _popup.IsInsidePopup(v))
{
SelectionBoxItem = v.Text;
var container = v.FindLogicalAncestorOfType<TreeComboBoxItem>();
container?.SetValue(IsSelectedProperty, true);
if (container?.Header is Control control)
{
SelectionBoxItem = control.DataContext ?? control.ToString();
// UpdateSelectionFromEventSource(e.Source);
}
else
{
SelectionBoxItem = container?.Header;
// UpdateSelectionFromEventSource(e.Source);
}
SetCurrentValue(IsDropDownOpenProperty, false);
}
else

View File

@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Mixins;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
@@ -45,6 +46,13 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
protected set => SetAndRaise(LevelProperty, ref _level, value);
}
static TreeComboBoxItem()
{
IsSelectedProperty.AffectsPseudoClass<TreeComboBoxItem>(PseudoClassName.PC_Selected,
SelectingItemsControl.IsSelectedChangedEvent);
PressedMixin.Attach<TreeComboBoxItem>();
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
@@ -57,14 +65,15 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
{
base.OnAttachedToLogicalTree(e);
_treeComboBox = this.FindLogicalAncestorOfType<TreeComboBox>();
Level = CalculateDistanceFromLogicalParent<TreeComboBox>(this);
Level = CalculateDistanceFromLogicalParent<TreeComboBox>(this) - 1;
if (this.ItemTemplate is null && this._treeComboBox?.ItemTemplate is not null)
{
SetCurrentValue(ItemTemplateProperty, this._treeComboBox.ItemTemplate);
}
if(this.ItemContainerTheme is null && this._treeComboBox?.ItemContainerTheme is not null)
{
SetCurrentValue(ItemContainerThemeProperty, this._treeComboBox.ItemContainerTheme);
}
}
private void OnDoubleTapped(object sender, TappedEventArgs e)
@@ -76,6 +85,8 @@ public class TreeComboBoxItem: HeaderedItemsControl, ISelectable
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
{
TreeViewItem t = new TreeViewItem();
ComboBox c = new ComboBox();
return EnsureParent().NeedsContainerInternal(item, index, out recycleKey);
}