feat: remove virtualization subscription feature to avoid potential issue of
This commit is contained in:
@@ -7,6 +7,7 @@ using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Interactivity;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
@@ -59,35 +60,9 @@ public class MultiComboBox: SelectingItemsControl
|
||||
return new MultiComboBoxItem();
|
||||
}
|
||||
|
||||
private Dictionary<int, IDisposable?> _disposables = new Dictionary<int, IDisposable?>();
|
||||
|
||||
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
|
||||
{
|
||||
base.PrepareContainerForItemOverride(container, item, index);
|
||||
if(_disposables.TryGetValue(index, out var d))
|
||||
{
|
||||
d?.Dispose();
|
||||
_disposables.Remove(index);
|
||||
}
|
||||
if (container is MultiComboBoxItem comboBoxItem)
|
||||
{
|
||||
comboBoxItem.IsSelected = SelectedItems?.Contains(item) ?? false;
|
||||
var disposable = MultiComboBoxItem.IsSelectedProperty.Changed.Subscribe(a =>
|
||||
{
|
||||
if (a.Sender == comboBoxItem)
|
||||
{
|
||||
if (comboBoxItem.IsSelected)
|
||||
{
|
||||
SelectedItems?.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedItems?.Remove(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
_disposables[index] = disposable;
|
||||
}
|
||||
}
|
||||
|
||||
internal void ItemFocused(MultiComboBoxItem dropDownItem)
|
||||
@@ -97,5 +72,4 @@ public class MultiComboBox: SelectingItemsControl
|
||||
dropDownItem.BringIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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