fix: fix container selection state issue.
This commit is contained in:
@@ -13,6 +13,7 @@ public class MultiComboBoxItem: ContentControl
|
||||
private MultiComboBox? _parent;
|
||||
private static readonly Point s_invalidPoint = new (double.NaN, double.NaN);
|
||||
private Point _pointerDownPoint = s_invalidPoint;
|
||||
private bool _updateInternal;
|
||||
|
||||
public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<MultiComboBoxItem, bool>(
|
||||
nameof(IsSelected));
|
||||
@@ -34,6 +35,7 @@ public class MultiComboBoxItem: ContentControl
|
||||
|
||||
private void OnSelectionChanged(AvaloniaPropertyChangedEventArgs<bool> args)
|
||||
{
|
||||
if (_updateInternal) return;
|
||||
var parent = this.FindLogicalAncestorOfType<MultiComboBox>();
|
||||
if (args.NewValue.Value)
|
||||
{
|
||||
@@ -94,4 +96,15 @@ public class MultiComboBoxItem: ContentControl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
_updateInternal = true;
|
||||
if (_parent?.ItemsPanelRoot is VirtualizingPanel)
|
||||
{
|
||||
IsSelected = _parent?.SelectedItems?.Contains(DataContext) ?? false;
|
||||
}
|
||||
_updateInternal = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user