-
Notifications
You must be signed in to change notification settings - Fork 686
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
Proposal: Add override-aware indirection support to the XAML resource lookup system #2913
Comments
@MikeHillberg and @kikisaints FYI. I know we have discussed this area in the past. The major concern here is perf. |
Yep, this is a huge point of confusion with the existing resource system. There are some performance reasons why it is the way it is, but the confusion in my opinion greatly outweighs that. Fundamentally it doesn't behave the way that developers expect. I'd love to fix this, even if it means creating a new resource reference type or system and phasing out the old (e.g. x:Bind versus Binding). |
Has there been any discussion surrounding this? Would really make lightweight styling more powerful and useful |
Proposal: Add override-aware indirection support to the XAML resource lookup system
Summary
Currently, the XAML resource lookup system does not have support for override-aware indirection. By that I mean the following: If we have two resources with one resource referencing the other, the referencing resource should pick up developer-provided overrides of the referenced theme resource when in scope. To illustrate this, please take a look at the following XAML:
And some XAML where these resources are consumed:
In the code above, we are creating two rectangles side-by-side with one rectangle consuming the referenced resource directly (
BaseBrush
) and the other rectangle consuming the referencing resource (BaseBrushInheritor
). As we would expect, both rectangles are displayed in the correct color:The issue arises when we now override the referenced resource, like so:
This gives us the following result:
As we can see, the rectangle consuming the referenced resource (
BaseBrush
) correctly picked up our local override. However, the referencing resource did not. It still uses the the orginal value of the referenced theme resource, even though we have overriden that one in the correct scope. Ideally, the result here would be both rectangles displayed in an orange color.I have attached a demo app featuring this code below.
Rationale
Adding support to the resource lookup system to pick up updates to referenced resources and make them available through the referencing resources will enable at least the following two scenarios:
TextBox
,ComboBox
andNumberBox
controls. All three controls have a Description API and the foreground appearance can be configured by overriding theSystemControlDescriptionTextForegroundBrush
theme resource. In other words, overriding this resource on the app level, for example, will apply to the descriptions of all in-app TextBox, CombBox and NumberBox controls. However, for a consistent and easily discoverable lightweight-styling experience we should also think about adding specific theme resources likeTextBoxDescriptionForeground
,ComboBoxDescriptionForeground
andNumberBoxDescriptionForeground
. These three theme resources would reference the "parent" theme resourceSystemControlDescriptionTextForegroundBrush
so all overrides applied to it will still propagate down to its "child" theme resources while still allowing developers to pick a unique description foreground appearance for all three controls if they so wish. A discussion about this specific topic can be found here.Additional context
There's also a perhaps related issue where resource lookup initiated by binding functions does not pick up overriden resources. You can find more info about that here.
Attached files
XamlResourceSystemLookupDemo.zip
The text was updated successfully, but these errors were encountered: