maui-samples icon indicating copy to clipboard operation
maui-samples copied to clipboard

Setting BackgroundColor of AnimalTemplate, disables the backgroundColor style of the grid element

Open Legends opened this issue 2 years ago • 0 comments

Repo: https://github.com/dotnet/maui-samples/tree/main/8.0/Fundamentals/Shell

When I set the Background|BackgroundColor property for DataTemplate "AnimalTemplate": App.xaml:

<DataTemplate x:Key="AnimalTemplate">
    <Grid Padding="10"
         Background="Pink" ....

the setting above disables the BackgroundColor settings for the selected state for targettype Grid inside of CatsPage.xaml:

CatsPage.xaml:

<ContentPage.Resources>
     <Style TargetType="Grid">
         <Setter Property="VisualStateManager.VisualStateGroups">
             <VisualStateGroupList>
                 <VisualStateGroup x:Name="CommonStates">
                     <VisualState x:Name="Normal" />
                     <VisualState x:Name="Selected">
                         <VisualState.Setters>
                             <Setter Property="BackgroundColor"
                                     Value="Green" />
                         </VisualState.Setters>
                     </VisualState>
                 </VisualStateGroup>
             </VisualStateGroupList>
         </Setter>
     </Style>
 </ContentPage.Resources>

AnimalTemplate is the ItemTemplate for the CollectionView.

Result: Items' BackgroundColor doesn't change.

Expected Result: Selected items'backgroundColor changes to green background.


Repro:

  1. Add Background="Pink" to DataTemplate x:Key="AnimalTemplate" in App.xaml
  2. Run the app
  3. Select a cat
  4. Navigate back to CatsPage.xaml

The previously selected cat is in selected state, but backgroundColor didn't change.

Legends avatar Feb 01 '24 15:02 Legends