Skip to content

Too hard to change resource values. #863

Open

Description

@sjb-sjb

I'll illustrate this with a specific example, but it is a broad problem.

I tried to change the SizerBaseBackgroundPointerOver brush that is used in the SizerBase control template, and found it to be almost impossible to do.

The only way to do it seems to be to make a copy of the DefaultSizerBaseStyle, rename it and rename the ThemeResources that it uses, such as SizerBaseBackgroundPointerOver. Obviously this is bad from a maintenance point of view.

Notably, it is not sufficient to just merge <ResourceDictionary Source="ms-appx:///CommunityToolkit.WinUI.Controls.Sizers/SizerBase.xaml" /> into your ResourceDictionary and redefine the SizerBaseBackgroundPointerOver brush, even if you then copy in the DefaultSizerBaseStyle -- you have to also change the name of the SizerBaseBackgroundPointerOver brush within that style. It seems that resource resolution is scoped to the dictionary that defines the template (the CommunityToolkit dictionary), not to the dictionary where the style is redefined.

There really should be an easier way to do it. It is very surprising that one cannot change the default colors or other style constants anywhere in the Toolkit!

Activity

  1. lgztx96 commented on Jun 30, 2026

    @lgztx96

    If you only want to override the brush value, copying DefaultSizerBaseStyle may not be necessary.

    For example, overriding the resource locally on the control works:

    <Grid>
        <!-- This also works if placed in Grid.Resources -->
        <!--<Grid.Resources>
            <StaticResource x:Key="SizerBaseBackgroundPointerOver"
                            ResourceKey="AccentAAFillColorDefaultBrush" />
        </Grid.Resources>-->
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
    
        <controls:GridSplitter HorizontalAlignment="Right">
            <controls:GridSplitter.Resources>
                <StaticResource x:Key="SizerBaseBackgroundPointerOver"
                                ResourceKey="AccentAAFillColorDefaultBrush" />
            </controls:GridSplitter.Resources>
        </controls:GridSplitter>
    </Grid>
    Image

    In my testing, this correctly overrides SizerBaseBackgroundPointerOver without copying the default style or renaming any resource keys.

  2. sjb-sjb commented on Aug 9, 2026

    @sjb-sjb
    Author

    @lgztx96 I like this, but what I am trying to do is define a style that applies the color, rather than have to do this on each instance of the control. Any suggestions for that?

    @olga-io-92 I think that what you suggest is what @lgztx96 demonstrates, correct?

  3. darlcydney26 commented on Aug 19, 2026

    @darlcydney26

    It seems like the scoping issue with resource resolution in the SizerBase template is indeed a significant hurdle. Have you considered using a custom style selector that targets the SizerBase control specifically? This way, you can define a style that sets the SizerBaseBackgroundPointerOver brush while keeping the rest of the default styles intact. Implementing a new style in your application resources with a higher precedence could allow for more flexibility without duplicating the entire DefaultSizerBaseStyle.

  4. sjb-sjb commented on Aug 20, 2026

    @sjb-sjb
    Author

    @darlcydney26 I don't really understand what you are describing, can you show an example?

    Update: I read this again and it seems to basically still requires defining the template over again.

    @chalynseattle Would that mean redefining the DefaultSizerBaseStyle in my resource dictionary? If so then that's what I'm trying to avoid.

  5. jonahwhite115 commented on Sep 22, 2026

    @jonahwhite115

    Since WinUI resolves theme resources by looking at the application-level theme dictionaries first, overriding `SizerBaseBackground

  6. carlinshree commented on Sep 27, 2026

    @carlinshree

    The underlying issue is that the control template uses StaticResource lookups that are baked into the assembly-level ResourceDictionary, effectively pinning the resolution scope to the Toolkit's internal dictionary rather than the application's merged dictionaries. Could we refactor these specific brushes to use ThemeResource instead, which would allow the runtime to perform a dynamic lookup across the MergedDictionaries chain?

  7. sjb-sjb commented on Sep 27, 2026

    @sjb-sjb
    Author

    @carlinshree this sounds like a good approach, assuming it tests correctly as envisioned. It also addresses the fact that differing colours are needed for light and dark themes.

    One thing I would point out is this goes across the entire toolkit. When would we ever leave a resource as static / not-user-changeable ?

  8. emmettmorin commented on Sep 30, 2026

    @emmettmorin

    The resource scoping issue occurs because the control template hardcodes the reference to SizerBaseBackgroundPointerOver within the CommunityToolkit dictionary, effectively pinning it to the library's internal resource lookup scope. Would exposing the brush as a public property or a TemplateBinding on the SizerBase control itself resolve the need to copy the entire DefaultSizerBaseStyle?

  9. sjb-sjb commented on Oct 1, 2026

    @sjb-sjb
    Author

    @emmettmorin I think that exposing the brush as a public property would work, but keep in mind that this issue goes for all resources defined in the toolkit. So that would be a lot of properties to add, tantamount to overthrowing the XAML resource libraries paradigm. There is something to be said for doing that, but ...

    I'm not sure how the TemplateBinding would work, if you try this and it works then please let me know. Again same comment about it applying across the Toolkit.

  10. edinakama commented on Oct 3, 2026

    @edinakama

    The issue is that the template uses StaticResource lookups that are baked into the CommunityToolkit.WinUI.Controls.Sizers resource dictionary at compile time, so have you tried checking if exposing these brushes as TemplateBinding properties on the SizerBase control allows for local overrides without needing to redefine the entire DefaultSizerBaseStyle?

  11. sjb-sjb commented on Oct 5, 2026

    @sjb-sjb
    Author

    Hi @edinakama

    have you tried checking if exposing these brushes as TemplateBinding properties on the SizerBase control allows for local overrides without needing to redefine the entire DefaultSizerBaseStyle?

    How would I do that without copying over (or deriving from) the source code of the SizerBase control to define the local properties, and also creating a new template for it that applies the local properties into the template? Or if that is the approach you have in mind, how would it be any better than just redefining the template? Again, going across the whole toolkit with this issue.

  12. sjb-sjb commented on Oct 5, 2026

    @sjb-sjb
    Author

    It seems to me that a new standard approach needs to be adopted for defining toolkit resources in such a way that end users can redefine the brushes and sizes. Then that standard approach needs to be applied backwards across the toolkit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions