Problems overwriting theme resources

Paul 21 Reputation points
2022-12-01T21:30:23.96+00:00

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>  

 
Universal Windows Platform (UWP)
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
725 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Paul 21 Reputation points
    2022-12-14T14:54:38.547+00:00

    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".