Skip to content

[WIP] Element RequestedTheme, ActualTheme - #3387

Closed
MartinZikmund wants to merge 11 commits into
unoplatform:masterfrom
MartinZikmund:dev/mazi/element-theme
Closed

MartinZikmund wants to merge 11 commits into
unoplatform:masterfrom
MartinZikmund:dev/mazi/element-theme

Conversation

@MartinZikmund

@MartinZikmund MartinZikmund commented Jun 17, 2020 •

Copy link
Copy Markdown
Member

GitHub Issue (If applicable): closes #3302

PR Type

What kind of change does this PR introduce?

  • Feature

What is the current behavior?

Element-level theming is not supported.

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@gitpod-io

gitpod-io Bot commented Jun 17, 2020 •

Copy link
Copy Markdown

Comment thread src/Uno.UI/UI/Xaml/FrameworkElement.cs Resolved
@MartinZikmund MartinZikmund self-assigned this Jun 21, 2020
Comment thread src/Uno.UI/UI/Xaml/FrameworkElement.cs Resolved
Comment thread src/Uno.UI/UI/Xaml/FrameworkElement.cs Resolved
Comment thread src/Uno.UI/UI/Xaml/FrameworkElement.cs Resolved
Comment thread src/Uno.UI/UI/Xaml/FrameworkElement.cs Resolved
@MartinZikmund

MartinZikmund commented Jul 2, 2020 •

Copy link
Copy Markdown
Member Author

@davidjohnoliver Have you been able to check #3388 yet, please? I have noticed it behaves unusually even for some non-visual state items. I will update the issue with a comment :-) .

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/element-theme branch from 65ccba1 to 15eb792 Compare July 3, 2020 08:19
@MartinZikmund

Copy link
Copy Markdown
Member Author

@davidjohnoliver @jeromelaban @dr1rrb Pushed new version, made several changes to the logic

  • both dependency properties now use inheritance
  • theme dictionary search does fallback to Default if the requested theme dictionary exists, but the searched key does not
  • added element theme support to some code paths which I previously didn't notice
  • removed default parameter values to make ElementTheme explicit

There is still a bit more work required, as I noticed BasicThemeResources sample does not yet work the same way as in UWP, so I will continue with this

@MartinZikmund

MartinZikmund commented Jul 3, 2020 •

Copy link
Copy Markdown
Member Author

@davidjohnoliver

Update

Maybe this will be a bit more complicated :-D . Consider the following:

<Page RequestedTheme="Light">
    <StackPanel RequestedTheme="Dark">
         <TextBlock>Hello</TextBlock>
    </StackPanel>
</Page>

In this case, the TextBlock should have white foreground, as Dark theme is applied to it. However, Foreground on TextBlock is set to "Inherit", so instead it inherits the Foreground from the nearest "Control" parent, which in this case is Page and will have black foreground. How do you think we could fix this?

Original comment

I found why the TextBlock color didn't update in my Messages sample - it seems that when TextBlock color is not explicitly set, it does not inherit its value from the container control's foreground. This causes an issue as the color stays on its default value. You can see this currently on the BasicThemeResources page when you switch to Local Dark theme - this top TextBlock which stays always black:
image

@davidjohnoliver

Copy link
Copy Markdown
Contributor

@davidjohnoliver

Update

Maybe this will be a bit more complicated :-D . Consider the following:

Indeed it may not be straightforward :D It seems to touch on this issue - #3443 . Inheritance predecence is tricky.

@MartinZikmund

MartinZikmund commented Jul 4, 2020 •

Copy link
Copy Markdown
Member Author

@davidjohnoliver Made another round of significant changes:

  • RequestedTheme no longer inherits - I noticed that setting it on a scope in UWP does not affect the children. Hence now changing performs a "tunneling" similar to when Application theme is set - both are now refactored to use a common FrameworkElement logic
  • I had to add precedence to ResourceBinding, as default style theme resources were overwriting the explicit style resources (as theme resource setting had previously used local precedence). I hope I didn't miss something, please double check this portion especially. This might also potentially help with the VisualStates problem too.
  • I had to add logic to update theme resources when parent of an element is changed. This is needed because during parsing, the parent is not yet set, so its resources cannot be found.
  • I have updated the ResourceDictionary indexer to throw when key is not found, to match UWP. I have found a commented out test for this, however so I am not sure if this was done for some specific reason? Maybe because we expect some resources may not yet exist like reveal brushes?
  • The Foreground of TextBlock works, but not sure if there is not some edge case still. That will probably need some more tests.

@MartinZikmund
MartinZikmund marked this pull request as ready for review July 5, 2020 09:34
@davidjohnoliver

Copy link
Copy Markdown
Contributor

@MartinZikmund Nice stuff, I'll take a look. :)

For the commented-out test, I suspect the behaviour might've been different for the older UWP 1709, but I can't remember for sure. It's fine to restore it if it matches the behaviour of the UWP version we're currently targeting.

@MartinZikmund

Copy link
Copy Markdown
Member Author

@MartinZikmund Nice stuff, I'll take a look. :)

For the commented-out test, I suspect the behaviour might've been different for the older UWP 1709, but I can't remember for sure. It's fine to restore it if it matches the behaviour of the UWP version we're currently targeting.

@davidjohnoliver Tested with the two latest SDKs and it seems both throws, so the exception should be ok.

@MartinZikmund
MartinZikmund requested review from a team, davidjohnoliver and jeromelaban July 20, 2020 08:50
Comment thread src/Uno.UI/UI/Xaml/Application.cs Resolved
@MartinZikmund

Copy link
Copy Markdown
Member Author

Oh ok, maybe there are still issues 😂😂😂
image

@MartinZikmund
MartinZikmund marked this pull request as draft July 20, 2020 15:50
@MartinZikmund
MartinZikmund marked this pull request as ready for review July 27, 2020 23:17
@jeromelaban jeromelaban reopened this Aug 13, 2020
@gitpod-io

gitpod-io Bot commented Aug 13, 2020

Copy link
Copy Markdown

@MartinZikmund

Copy link
Copy Markdown
Member Author

@davidjohnoliver Will we be able to merge this in some form so the element theme support can be worked on further?

@davidjohnoliver

Copy link
Copy Markdown
Contributor

@MartinZikmund We should be able to merge this, providing it doesn't introduce any regressions.

'No regressions' probably means preserving the current special-casing for Window.Current.Root, for which changing the RequestedTheme just changes the whole app theme behind the scenes, at least until we're sure that the current element-level logic fully matches it.

@jeromelaban

Copy link
Copy Markdown
Member

Is there something that changed about this PR, particularly the last comment ?

@MartinZikmund

Copy link
Copy Markdown
Member Author

Is there something that changed about this PR, particularly the last comment ?

@jeromelaban Ah, sorry, no. I didn't get to it since TreeView/TabView. Once I finish prepping TabView for merging, I will continue with this one to rebase on master and make sure to have it as a "alternative" for now, not to break the global setting.

@MartinZikmund
MartinZikmund force-pushed the dev/mazi/element-theme branch from fbf2488 to 6ca1a85 Compare August 1, 2021 11:22
@gitpod-io

gitpod-io Bot commented Aug 1, 2021

Copy link
Copy Markdown

@MartinZikmund MartinZikmund changed the title Element RequestedTheme, ActualTheme [WIP] Element RequestedTheme, ActualTheme Nov 9, 2021
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or it will be closed in 10 days.

@github-actions github-actions Bot added the stale This item has been marked as stale and will be closed if there is no activity. label Jan 29, 2025
@MartinZikmund MartinZikmund removed the stale This item has been marked as stale and will be closed if there is no activity. label Jul 31, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Element-level Theme

4 participants