fix: Selection logic
This commit is contained in:
Родитель
c9dde167e7
Коммит
8a6cc53164
|
@ -37,9 +37,12 @@ namespace Uno.UI.RuntimeTests.Tests.Microsoft_UI_Xaml_Controls
|
|||
finger.Press(tapTarget);
|
||||
finger.Release();
|
||||
|
||||
Assert.AreEqual(loggingSelectionInfo.IsSelected(0), true, "Item 0 should remain unselected.");
|
||||
Assert.AreEqual(loggingSelectionInfo.CurrentPosition, 0, "CurrentPosition should be 0 after the tap.");
|
||||
Assert.AreEqual(loggingSelectionInfo.CurrentItem, items[0], "CurrentItem should be 'Item 1' after the tap.");
|
||||
// Confirm that selection has been pushed to the source using the ISelectionInfo
|
||||
Assert.AreEqual(loggingSelectionInfo.IsSelected(0), true, "Item 0 should be selected now.");
|
||||
|
||||
// Confirm that the selection HAS NOT been pushed using the `ICollectionView`
|
||||
Assert.AreEqual(loggingSelectionInfo.CurrentPosition, -1, "CurrentPosition should not have been updated.");
|
||||
Assert.AreEqual(loggingSelectionInfo.CurrentItem, null, "CurrentItem should be not have been updated.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -611,7 +611,16 @@ namespace Microsoft.UI.Xaml.Controls
|
|||
{
|
||||
//The `ISelectionInfo` handled directly by the `ItemsSource` has precedence over the `ICollectionView`.
|
||||
//If an object implements both interfaces, as WinUI, we make sure to use only the `ISelectionInfo` to avoid conflicting interaction.
|
||||
if (ItemsSource is ICollectionView collectionView and not ISelectionInfo)
|
||||
|
||||
// Ensure that we do not alter the selection if ISelectionInfo is in use
|
||||
if (ItemsSource is ISelectionInfo)
|
||||
{
|
||||
// The selection will be managed by ISelectionInfo, so we do nothing here.
|
||||
// This prevents ICollectionView from interfering with the selection logic.
|
||||
return;
|
||||
}
|
||||
|
||||
if (ItemsSource is ICollectionView collectionView && !(ItemsSource is ISelectionInfo))
|
||||
{
|
||||
//NOTE: Windows seems to call MoveCurrentTo(item); we set position instead to have expected behavior when you have duplicate items in the list.
|
||||
collectionView.MoveCurrentToPosition(clickedIndex);
|
||||
|
|
Загрузка…
Ссылка в новой задаче