I use WinUI3 and if found a working solution: Overwrite GridViewItem style with a BasedOn property pointing to the original style. Because my problem was it would overwrite all the other style until i found out about the "based on".
Problems overwriting theme resources
Paul
21
Reputation points
Hi,
i want my GridViewItems have rounded corners and maybe no select animation. After some time i found following site with a resource table for the GridView:
So i tryed to overwrite the corner cardius and the selectedborderbrush in my application resources but it does not work:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="/Styles/FontSizes.xaml" />
<ResourceDictionary Source="/Styles/Thickness.xaml" />
<ResourceDictionary Source="/Styles/TextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
<CornerRadius x:Key="GridViewItemCornerRadius">15</CornerRadius>
<SolidColorBrush x:Key="GridViewItemSelectedBorderBrush" Color="Chartreuse" />
</ResourceDictionary>
</Application.Resources>
Why does that not work, and what's my alternative?
...
I found following which does work but it's bad because it overwrites all default styling instead of only selected values:
GridView.ItemContainerStyle -> Style TargetType=GridViewItem ->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<GridViewItemPresenter SelectedBackground="Chartreuse" CornerRadius="15"/>
</ControlTemplate>
</Setter.Value>
</Setter>