Skip to content

Implicit styles for TextBlocks are used inside DataTemplates #3443

Open

Description

@peternary

Current behavior

Textblocks inside a DataTemplate have implicit styles applied to them.

Expected behavior

Only elements that inherit from Control should have implicit styles applied inside of a DataTemplate. TextBlock, which inherits from UIElement, should not have implicit styles applied.

How to reproduce it (as minimally and precisely as possible)

Launch the attached project in UWP and observe that the text inside the border is black, while the text outside the border is green. Launch in Wasm and observe that the text in both cases is green. The implicit style set in App.xaml is being applied to the TextBlock inside of the DataTemplate.

ImplicitStyleBoundary.zip

Environment

Nuget Package:
Uno.UI
Package Version(s):
3.0.0-dev.636
Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on Jun 25, 2020
  2. added
    project/styling 👔
    and removed
    triage/untriaged
    on Jun 29, 2020
  3. davidjohnoliver commented on Jul 3, 2020

    @davidjohnoliver
    Contributor

    The precedence rules of inheritance vs styling are fairly tricky on UWP. Some observations:

    • in the original repro, if the TextBlock is replaced by a Button, the implicit style does take precedence;
    • Templates are indeed treated differently. For the following Xaml snippet, the TextBlock set as Button.Content takes the TextBlock implicit style color, but the TextBlock in the template inherits the button's color:
    			<Button x:Name="parentButton"
    					Foreground="Blue" />
    			<Button Foreground="Blue">
    				<TextBlock Text="Text content" />
    			</Button>
    			<Button Foreground="Blue"
    					Content="Dummy">
    				<Button.ContentTemplate>
    					<DataTemplate>
    						<TextBlock Text="Text template" />
    					</DataTemplate>
    				</Button.ContentTemplate>
    			</Button>

    image

    • RegisterPropertyChangedCallback() is seemingly never called when the property is set by inheritance

    @peternary Can you elaborate on your use cases, ie do you have scenarios where this is problematic to work around? Eg, sometimes the workaround is to explicitly set the TextBlock's properties, but this doesn't work easily when the properties are being set by the visual state of a ListViewItem, for instance.

  4. peternary commented on Jul 6, 2020

    @peternary
    Author

    @davidjohnoliver In our case it was resulting in unexpected style differences between UWP and WASM for a ListView ItemTemplate. The specific issue is easy enough to work around once known (in our case simply applying a style to the TextBlock elements inside the ListView), but the differences in inheritance do make reliable styling more difficult to write.

  5. modified the milestone: 3.1 on Aug 28, 2020
  6. DierkDroth commented on Nov 25, 2020

    @DierkDroth

    @francoistanguay @jeromelaban doing some book keeping: is that issue addressed now and could be closed?

  7. jeromelaban commented on Nov 26, 2020

    @jeromelaban
    Member

    The issue is not addressed, and the workaround is still valid. DependencyProperty precedences are not behaving exactly the same way as WinUI does, and we'll be looking at those in the coming months.

  8. DierkDroth commented on Nov 27, 2020

    @DierkDroth

    Thanks for the update @jeromelaban

  9. added
    difficulty/tbd
    on Feb 15, 2021
  10. added
    difficulty/medium 🤔
    and removed
    difficulty/tbd
    on Jun 4, 2021
  11. changed the title [-][WASM] Implicit styles for TextBlocks are used inside DataTemplates[/-] [+]Implicit styles for TextBlocks are used inside DataTemplates[/+] on Jul 28, 2021
  12. changed the title [-]Implicit styles for TextBlocks are used inside DataTemplates[/-] [+]Implicit styles for `TextBlocks` are used inside `DataTemplates`[/+] on Jun 14, 2023
  13. MartinZikmund commented on Jul 17, 2025

    @MartinZikmund
    Member

    This should be validated as there were many related changes since, so it might be fixed

  14. added theissue type on Jul 17, 2025
  15. self-assigned this
    on Sep 9, 2025
  16. removed their assignment
    on Sep 17, 2025
  17. MartinZikmund commented on Jan 19, 2026

    @MartinZikmund
    Member

    @Jen-Uno similarly here, I see Khalil put it back to Ready for QA , but then it was moved directly to Done - was it really QAd?

  18. rajamatt commented on Jan 26, 2026

    @rajamatt
    Contributor

    Reopening, looks like TextBlocks still use implicit styles even when inside DataTemplates. Test6dot5.zip


    Tested with:
    Templates/SDK: 6.5.7 (which uses Uno version 6.5.31)
    Platform(s): Desktop
    IDE: Visual Studio 2026 18.2.1
    OS: Windows

  19. MartinZikmund commented on Apr 7, 2026

    @MartinZikmund
    Member

    Repro generator

    Runtime test(s) added in branch dev/mazi/repro/3443:

    • src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_Style.cs → When_TextBlock_ImplicitStyle_Not_Applied_Inside_DataTemplate

    The test fails as expected on Skia Desktop: the TextBlock inside the DataTemplate receives the green foreground color (#FF008000) from the implicit style, when it should retain the default black foreground. Both the inside and outside TextBlock get the implicit style, confirming implicit styles leak through the DataTemplate boundary.

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

    difficulty/medium 🤔has-repro-branchkind/bugproject/styling 👔

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions