Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
28e017a
Commit for SelectedItem
SuthiYuvaraj Oct 28, 2024
8abfec8
Update Issue25551.xaml
SuthiYuvaraj Oct 28, 2024
d4ffe0b
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Oct 29, 2024
2d158c2
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Oct 29, 2024
a958b61
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Oct 30, 2024
c22ab95
Commit for testcases
SuthiYuvaraj Oct 30, 2024
d9cb970
Commit for image
SuthiYuvaraj Oct 30, 2024
0107ce7
Update SelectableItemsViewController.cs
SuthiYuvaraj Oct 30, 2024
bac9ca4
Commit for changes
SuthiYuvaraj Oct 30, 2024
486a3a9
Update SelectableItemsViewController.cs
SuthiYuvaraj Oct 30, 2024
66d5b3a
Update SelectableItemsViewController2.cs
SuthiYuvaraj Oct 30, 2024
358ca1e
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Nov 1, 2024
02caf0d
Commit for images
SuthiYuvaraj Nov 1, 2024
36049cf
Commit for SelectedItem
SuthiYuvaraj Oct 28, 2024
01a7a9f
Update Issue25551.xaml
SuthiYuvaraj Oct 28, 2024
6d3fdc7
Commit for testcases
SuthiYuvaraj Oct 30, 2024
45f1388
Commit for image
SuthiYuvaraj Oct 30, 2024
db1de31
Update SelectableItemsViewController.cs
SuthiYuvaraj Oct 30, 2024
3e47a4c
Commit for changes
SuthiYuvaraj Oct 30, 2024
56f98b3
Update SelectableItemsViewController.cs
SuthiYuvaraj Oct 30, 2024
18b20e8
Update SelectableItemsViewController2.cs
SuthiYuvaraj Oct 30, 2024
0294624
Commit for images
SuthiYuvaraj Nov 1, 2024
f0c2588
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Nov 5, 2024
8b25efe
Merge branch 'SyncToolKit' of https://github.com/SuthiYuvaraj/maui in…
SuthiYuvaraj Nov 5, 2024
c1ac334
Commit for multiple selection
SuthiYuvaraj Nov 5, 2024
e1bec77
Commit for images
SuthiYuvaraj Nov 5, 2024
ac74771
commit for image changes
SuthiYuvaraj Nov 5, 2024
9b60d74
commit for image remoced
SuthiYuvaraj Nov 5, 2024
dabc113
image removed for windows
SuthiYuvaraj Nov 5, 2024
515cf52
Added the windows platform output image
NanthiniMahalingam Nov 6, 2024
2217a15
Merge branch 'main' of https://github.com/SuthiYuvaraj/maui into Sync…
NanthiniMahalingam Nov 6, 2024
ec8804f
Merge branch 'dotnet:main' into SyncToolKit
SuthiYuvaraj Nov 15, 2024
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 @@ -206,6 +206,14 @@ void UpdateItemContentControlSelection()
}
}

protected override void UpdateItemsLayout()
{
_ignorePlatformSelectionChange = true;

base.UpdateItemsLayout();
_ignorePlatformSelectionChange = false;
}

protected override void UpdateItemsSource()
{
_ignorePlatformSelectionChange = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ internal void SelectItem(object selectedItem)

if (index.Section > -1 && index.Item > -1)
{
CollectionView.SelectItem(index, true, UICollectionViewScrollPosition.None);
// Ensure the selected index is updated after the collection view's items generation is completed
CollectionView.PerformBatchUpdates(null, _ =>
{
CollectionView.SelectItem(index, true, UICollectionViewScrollPosition.None);
});
}
}

Expand Down Expand Up @@ -168,4 +172,4 @@ void SynchronizePlatformSelectionWithSelectedItems()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ internal void SelectItem(object selectedItem)

if (index.Section > -1 && index.Item > -1)
{
CollectionView.SelectItem(index, true, UICollectionViewScrollPosition.None);
// Ensure the selected index is updated after the collection view's items generation is completed
CollectionView.PerformBatchUpdates(null, _ =>
{
CollectionView.SelectItem(index, true, UICollectionViewScrollPosition.None);
});
}
}

Expand Down Expand Up @@ -168,4 +172,4 @@ void SynchronizePlatformSelectionWithSelectedItems()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ internal void Realize()
}

itemsView?.AddLogicalChild(_visualElement);

if (itemsView is SelectableItemsView selectableItemsView && selectableItemsView.SelectionMode is not SelectionMode.None)
{
bool isSelected = false;
if (selectableItemsView.SelectionMode == SelectionMode.Single)
isSelected = selectableItemsView.SelectedItem == FormsDataContext;
else
isSelected = selectableItemsView.SelectedItems.Contains(FormsDataContext);

if (isSelected)
UpdateIsSelected(isSelected);
}
}

void SetNativeStateConsistent(VisualElement visualElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*REMOVED*~Microsoft.Maui.Controls.NavigableElement.StyleClass.get -> System.Collections.Generic.IList<string>
*REMOVED*~Microsoft.Maui.Controls.NavigableElement.StyleClass.set -> void
Microsoft.Maui.Controls.HybridWebView.SetInvokeJavaScriptTarget<T>(T! target) -> void
override Microsoft.Maui.Controls.Handlers.Items.SelectableItemsViewHandler<TItemsView>.UpdateItemsLayout() -> void
~Microsoft.Maui.Controls.ResourceDictionary.SetAndCreateSource<T>(System.Uri value) -> void
*REMOVED*~Microsoft.Maui.Controls.ResourceDictionary.SetAndLoadSource(System.Uri value, string resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) -> void
~Microsoft.Maui.Controls.WebViewProcessTerminatedEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformWebViewProcessTerminatedEventArgs
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25551.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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.Issue25551"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">

<VerticalStackLayout>
<CollectionView AutomationId="SingleSelection"
Margin="15,0,0,15"
SelectionMode="Single"
HeightRequest="300"
ItemsSource="{Binding Items}"
SelectedItem="{Binding SelectedItem}"
VerticalOptions="Center">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" ItemSpacing="10"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid RowDefinitions="Auto,4" RowSpacing="5">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter TargetName="SelectedIndicator" Property="BoxView.IsVisible" Value="False"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
<Setter TargetName="SelectedIndicator" Property="BoxView.IsVisible" Value="True"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Label
Text="{Binding .}"
x:Name="ItemName"
FontAttributes="Bold"
FontSize="14"
VerticalOptions="Center"
HorizontalOptions="Center"
TextColor="Green"/>
<BoxView x:Name="SelectedIndicator" Color="blue" HeightRequest="4" HorizontalOptions="Fill" Grid.Row="1"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>

</CollectionView>

<CollectionView AutomationId="MultipleSelection"
Margin="15,0,0,15"
SelectionMode="Multiple"
HeightRequest="300"
ItemsSource="{Binding Items}"
SelectedItems="{Binding SelectedItems}"
VerticalOptions="Center">
<CollectionView.ItemsLayout>
<LinearItemsLayout Orientation="Horizontal" ItemSpacing="10"/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid RowDefinitions="Auto,4" RowSpacing="5">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter TargetName="SelectedIndicator" Property="BoxView.IsVisible" Value="False"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter Property="Background" Value="Transparent"/>
<Setter TargetName="SelectedIndicator" Property="BoxView.IsVisible" Value="True"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Label
Text="{Binding .}"
x:Name="ItemName"
FontAttributes="Bold"
FontSize="14"
VerticalOptions="Center"
HorizontalOptions="Center"
TextColor="Green"/>
<BoxView x:Name="SelectedIndicator" Color="blue" HeightRequest="4" HorizontalOptions="Fill" Grid.Row="1"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>

</CollectionView>
</VerticalStackLayout>
</ContentPage>
26 changes: 26 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25551.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25551, "CollectionView SelectedItem binding issue on initial loading",
PlatformAffected.All)]
public partial class Issue25551 : ContentPage
{
public string SelectedItem { get; set; }

public ObservableCollection<string> Items { get; set; }
public List<object> SelectedItems { get; set; }

public Issue25551()
{
InitializeComponent();
SelectedItems = new List<object>();
Items = new ObservableCollection<string> { "A", "B", "C", "D", "E", "F" };
SelectedItem = Items[0];
SelectedItems.Add(Items[1]);
SelectedItems.Add(Items[3]);
BindingContext = this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework.Legacy;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Tests.Issues
{
internal class Issue25551 : _IssuesUITest
{
public override string Issue => "CollectionView SelectedItem binding issue on initial loading";

public Issue25551(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.CollectionView)]

public void CollectionViewPreSelectionShouldUpdate()
{
App.WaitForElement("SingleSelection");
VerifyScreenshot();
App.WaitForElement("MultipleSelection");
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.