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 @@ -181,6 +181,7 @@ internal void Realize()
}

_visualElement.BindingContext = dataContext;
itemsView?.AddLogicalChild(_visualElement);
_handler = _visualElement.ToHandler(mauiContext);

Comment thread
Dhivya-SF4094 marked this conversation as resolved.
// We need to set IsPlatformStateConsistent explicitly; otherwise, it won't be set until the renderer's Loaded
Expand All @@ -198,6 +199,10 @@ internal void Realize()
{
// We are reusing this ItemContentControl and we can reuse the Element
_visualElement.BindingContext = dataContext;

// Re-add to the logical tree after RemoveLogicalChild was called at the top of Realize(),
// so styles, resources, and VSM states continue to resolve correctly on recycled cells.
itemsView?.AddLogicalChild(_visualElement);
}

if (_handler.VirtualView is ICrossPlatformLayout)
Expand All @@ -209,8 +214,6 @@ internal void Realize()
Content = new ContentLayoutPanel(_handler.VirtualView);
}

itemsView?.AddLogicalChild(_visualElement);

if (itemsView is SelectableItemsView selectableItemsView && selectableItemsView.SelectionMode is not SelectionMode.None)
{
bool isSelected = false;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 28 additions & 19 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22104.xaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<?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"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue22104"
x:DataType="local:Issue22104ViewModel">
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
x:Class="Maui.Controls.Sample.Issues.Issue22104"
x:DataType="local:Issue22104ViewModel">

<ContentPage.BindingContext>
<local:Issue22104ViewModel/>
</ContentPage.BindingContext>

<ContentPage.Resources>
<Style TargetType="Label">
<Setter Property="TextColor"
Value="Blue"/>
<Setter Property="Background"
Value="Transparent"/>
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="TextColor" Value="Black"/>
<Setter Property="TextColor"
Value="Black"/>
<Setter Property="Background"
Value="AliceBlue"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="TextColor" Value="Red"/>
<Setter Property="TextColor"
Value="Blue"/>
<Setter Property="Background"
Value="Red"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand All @@ -31,25 +40,25 @@
</ContentPage.Resources>

<VerticalStackLayout
Padding="30,0"
Spacing="25">
Padding="30,0"
Spacing="25">
<Image
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight" />
Source="dotnet_bot.png"
HeightRequest="185"
Aspect="AspectFit"
SemanticProperties.Description="dot net bot in a race car number eight"/>

<Button AutomationId="Button"
Text="Select Next"
Command="{Binding SelectNextCommand}"
HorizontalOptions="Fill" />
HorizontalOptions="Fill"/>

<Label
Text="{Binding LabelText}" />
<Label Text="{Binding LabelText}"/>

<CollectionView AutomationId="CollectionView" ItemsSource="{Binding List}"
SelectionMode="Single"
SelectedItem="{Binding SelectedItem}">
<CollectionView AutomationId="CollectionView"
ItemsSource="{Binding List}"
SelectionMode="Single"
SelectedItem="{Binding SelectedItem}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<Label Text="{Binding .}"/>
Expand Down
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading