Skip to content
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 @@ -140,14 +140,17 @@ internal void UpdateSelectionMode()
case SelectionMode.None:
CollectionView.AllowsSelection = false;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = true;
break;
case SelectionMode.Single:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = false;
break;
case SelectionMode.Multiple:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = true;
ClearsSelectionOnViewWillAppear = false;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ internal void UpdateSelectionMode()
case SelectionMode.None:
CollectionView.AllowsSelection = false;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = true;
break;
case SelectionMode.Single:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = false;
break;
case SelectionMode.Multiple:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = true;
ClearsSelectionOnViewWillAppear = false;
break;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22467.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22467"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">
<Grid>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<CollectionView x:Name="ResultCollectionView"
AutomationId="CollectionView"
Grid.Row="0"
MinimumHeightRequest="150"
MaximumHeightRequest="300"
SelectionMode="Single">

<CollectionView.ItemTemplate>
<DataTemplate>
<VerticalStackLayout>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal"/>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="LightGreen"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Label Text="{Binding}"
FontSize="14"
VerticalTextAlignment="Center"
Margin="25,7,7,7"/>

<BoxView HeightRequest="1"
BackgroundColor="Black"/>

</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

<Button Grid.Row="1"
x:Name="CounterBtn"
AutomationId="PushModalAsyncButton"
Text="Push New Page"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="CounterBtn_Clicked"
HorizontalOptions="Fill"/>
</Grid>
</ContentPage>
45 changes: 45 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22467.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22467, "CollectionView SelectedItem Background Reset After Modal Navigation", PlatformAffected.iOS)]
public partial class Issue22467 : ContentPage
{
public Issue22467()
{
InitializeComponent();
List<string> list = new() { "1", "2", "3", "4", "5" };
ResultCollectionView.ItemsSource = list;
ResultCollectionView.SelectedItem = list[3];
}

private async void CounterBtn_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(CreateNewPage1());
}

private ContentPage CreateNewPage1()
{
var newPage = new ContentPage
{
Title = "NewPage1",
Content = new VerticalStackLayout
{
Children =
{
new Button
{
Text = "Pop to Main Page",
AutomationId = "PopModalAsyncButton",
Command = new Command(async () =>
{
await Navigation.PopModalAsync(true);
})
}
}
}
};

return newPage;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue22467 : _IssuesUITest
{
public Issue22467(TestDevice device) : base(device) { }

public override string Issue => "CollectionView SelectedItem Background Reset After Modal Navigation";

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewSelectedItemBackgroundShouldPersistAfterModalNavigation()
{
App.WaitForElement("CollectionView");
App.Tap("PushModalAsyncButton");
App.WaitForElement("PopModalAsyncButton");
App.Tap("PopModalAsyncButton");
App.WaitForElement("CollectionView");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.