unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.89k stars 720 forks source link

Implicit styles for `TextBlocks` are used inside `DataTemplates` #3443

Open peternary opened 4 years ago

peternary commented 4 years ago

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?

davidjohnoliver commented 4 years ago

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


@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.

peternary commented 4 years ago

@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 commented 3 years ago

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

jeromelaban commented 3 years ago

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.

DierkDroth commented 3 years ago

Thanks for the update @jeromelaban