You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implicit styles for TextBlocks are used inside DataTemplates #3443
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.
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:
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.
@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.
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.
changed the title [-][WASM] Implicit styles for TextBlocks are used inside DataTemplates[/-][+]Implicit styles for TextBlocks are used inside DataTemplates[/+]on Jul 28, 2021
changed the title [-]Implicit styles for TextBlocks are used inside DataTemplates[/-][+]Implicit styles for `TextBlocks` are used inside `DataTemplates`[/+]on Jun 14, 2023
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.
Activity
davidjohnoliver commentedon Jul 3, 2020
The precedence rules of inheritance vs styling are fairly tricky on UWP. Some observations:
TextBlockis replaced by aButton, the implicit style does take precedence;TextBlockset asButton.Contenttakes theTextBlockimplicit style color, but theTextBlockin the template inherits the button's color: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 aListViewItem, for instance.peternary commentedon Jul 6, 2020
@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.
DierkDroth commentedon Nov 25, 2020
@francoistanguay @jeromelaban doing some book keeping: is that issue addressed now and could be closed?
jeromelaban commentedon Nov 26, 2020
The issue is not addressed, and the workaround is still valid.
DependencyPropertyprecedences are not behaving exactly the same way as WinUI does, and we'll be looking at those in the coming months.DierkDroth commentedon Nov 27, 2020
Thanks for the update @jeromelaban
[-][WASM] Implicit styles for TextBlocks are used inside DataTemplates[/-][+]Implicit styles for TextBlocks are used inside DataTemplates[/+][-]Implicit styles for TextBlocks are used inside DataTemplates[/-][+]Implicit styles for `TextBlocks` are used inside `DataTemplates`[/+]MartinZikmund commentedon Jul 17, 2025
This should be validated as there were many related changes since, so it might be fixed
MartinZikmund commentedon Jan 19, 2026
@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?
rajamatt commentedon Jan 26, 2026
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
test: Reproduce implicit styles leaking into DataTemplates for TextBlock
MartinZikmund commentedon Apr 7, 2026
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_DataTemplateThe test fails as expected on Skia Desktop: the
TextBlockinside theDataTemplatereceives the green foreground color (#FF008000) from the implicit style, when it should retain the default black foreground. Both the inside and outsideTextBlockget the implicit style, confirming implicit styles leak through the DataTemplate boundary.