feat: remove virtualization subscription feature to avoid potential issue of
This commit is contained in:
@@ -2,12 +2,15 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.LogicalTree;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class MultiComboBoxItem: ContentControl
|
||||
{
|
||||
private MultiComboBox? _parent;
|
||||
|
||||
public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<MultiComboBoxItem, bool>(
|
||||
nameof(IsSelected));
|
||||
|
||||
@@ -22,7 +25,23 @@ public class MultiComboBoxItem: ContentControl
|
||||
IsSelectedProperty.AffectsPseudoClass<MultiComboBoxItem>(":selected");
|
||||
PressedMixin.Attach<MultiComboBoxItem>();
|
||||
FocusableProperty.OverrideDefaultValue<MultiComboBoxItem>(true);
|
||||
IsSelectedProperty.Changed.AddClassHandler<MultiComboBoxItem, bool>((item, args) =>
|
||||
item.OnSelectionChanged(args));
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(AvaloniaPropertyChangedEventArgs<bool> args)
|
||||
{
|
||||
var parent = this.FindLogicalAncestorOfType<MultiComboBox>();
|
||||
if (args.NewValue.Value)
|
||||
{
|
||||
parent?.SelectedItems?.Add(this.DataContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent?.SelectedItems?.Remove(this.DataContext);
|
||||
}
|
||||
}
|
||||
|
||||
public MultiComboBoxItem()
|
||||
{
|
||||
this.GetObservable(IsFocusedProperty).Subscribe(a=> {
|
||||
@@ -32,7 +51,15 @@ public class MultiComboBoxItem: ContentControl
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_parent = this.FindLogicalAncestorOfType<MultiComboBox>();
|
||||
if(this.IsSelected)
|
||||
_parent?.SelectedItems?.Add(this.DataContext);
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
|
||||
Reference in New Issue
Block a user