Open peternary opened 4 years ago
The precedence rules of inheritance vs styling are fairly tricky on UWP. Some observations:
TextBlock
is replaced by a Button
, the implicit style does take precedence;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>
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.
@francoistanguay @jeromelaban doing some book keeping: is that issue addressed now and could be closed?
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.
Thanks for the update @jeromelaban
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):
Visual Studio:
Relevant plugins:
Anything else we need to know?