Merge pull request #735 from EjiHuang/fix/duplicate-items-in-multicombobox

fix: Prevent duplicate items in MultiComboBox SelectedItems by adding…
This commit is contained in:
Dong Bin
2025-07-25 11:38:55 +08:00
committed by GitHub

View File

@@ -52,8 +52,13 @@ public class MultiComboBoxItem: ContentControl
{ {
base.OnAttachedToLogicalTree(e); base.OnAttachedToLogicalTree(e);
_parent = this.FindLogicalAncestorOfType<MultiComboBox>(); _parent = this.FindLogicalAncestorOfType<MultiComboBox>();
if(this.IsSelected) if (this.IsSelected &&
_parent?.SelectedItems?.Add(this.DataContext); _parent is not null &&
_parent.SelectedItems is not null &&
!_parent.SelectedItems.Contains(this.DataContext))
{
_parent.SelectedItems.Add(this.DataContext);
}
} }
protected override void OnPointerPressed(PointerPressedEventArgs e) protected override void OnPointerPressed(PointerPressedEventArgs e)