Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix CollectionView DisconnectHandler SelectionMode Crash #23726

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected override void DisconnectHandler(ListViewBase platformView)

if (oldListViewBase != null)
{
oldListViewBase.ClearValue(ListViewBase.SelectionModeProperty);
oldListViewBase.SelectionChanged -= PlatformSelectionChanged;
oldListViewBase.ClearValue(ListViewBase.SelectionModeProperty);
}

if (ItemsView != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
Expand Down Expand Up @@ -58,6 +59,51 @@ await CreateHandlerAndAddToWindow<LayoutHandler>(layout, (handler) =>
});
}

[Fact(DisplayName = "CollectionView Disconnects Correctly with MultiSelection")]
public async Task CollectionViewHandlerDisconnectsWithMultiSelect()
{
SetupBuilder();

ObservableCollection<string> data = new ObservableCollection<string>()
{
"Item 1",
"Item 2",
"Item 3"
};

var collectionView = new CollectionView()
{
ItemTemplate = new Controls.DataTemplate(() =>
{
return new VerticalStackLayout()
{
new Label()
};
}),
SelectionMode = SelectionMode.Multiple,
ItemsSource = data
};

var layout = new VerticalStackLayout()
{
collectionView
};

await CreateHandlerAndAddToWindow<LayoutHandler>(layout, (handler) =>
{
collectionView.SelectedItems.Add(data[0]);
collectionView.SelectedItems.Add(data[2]);

// Validate that no exceptions are thrown
var collectionViewHandler = (IElementHandler)collectionView.Handler;
collectionViewHandler.DisconnectHandler();

((IElementHandler)handler).DisconnectHandler();

return Task.CompletedTask;
});
}

[Fact]
public async Task ValidateItemContainerDefaultHeight()
{
Expand Down
Loading