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

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

Open
Legends opened this issue Feb 1, 2024 · 0 comments

Comments

@Legends
Copy link

Legends commented Feb 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant