maui-samples
maui-samples copied to clipboard
Setting BackgroundColor of AnimalTemplate, disables the backgroundColor style of the grid element
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:
- Add Background="Pink" to DataTemplate x:Key="AnimalTemplate" in
App.xaml - Run the app
- Select a cat
- Navigate back to CatsPage.xaml
The previously selected cat is in selected state, but backgroundColor didn't change.