question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implict style for ContentPage not working

See original GitHub issue

Description

Using implicit style with ContentPage as target type seems not to work.

This was an issue in Xamarin.Forms, too. See https://github.com/xamarin/Xamarin.Forms/issues/12350.

Steps to Reproduce

Add an implicit style in Styles.xaml targeting ContentPage. For example:

<Style TargetType="ContentPage">
        <Setter Property="BackgroundColor" Value="Red" />
        <Setter Property="Opacity" Value="0.5" />
</Style>

Expected outcome: all ContentPages should respect the style above. Actual outcome: The implicit style seems to be ignored.

Link to public reproduction project repository

https://github.com/Riccardo11/MarketGrowthStrategy

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

iOS Android

Affected platform versions

iOS 16 Android 11

Did you find any workaround?

Adding ApplyToDerivedTypes="True" seems to solve the bug.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
riccardominatocommented, Oct 26, 2022

Thank you for your answer.

If this is the behavior by design, shouldn’t it be documented? I wasn’t able to find any hint about the solution I proposed inside Microsoft documentation, nor some explicit reference to ContentPage acting like this.

1reaction
riccardominatocommented, Jul 7, 2023

@oliver-ec it’s all about that ApplyToDerivedTypes="True". Check the workaround in the issue description.

The weird thing is that you have to specify that attribute even if you have to set a style specifically for ContentPage and you don’t care about derived types. Otherwise it doesn’t work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

xaml - Content page property not set with implicit style
1 Answer 1 ... TargetType in style is set to ContextPage but the real type is ChooseProfileView. ... Developers should be aware that...
Read more >
Implicit Styles in Xamarin.Forms
An implicit style is one that's used by all controls of the same TargetType, without requiring each control to reference the style.
Read more >
How to design efficiently on Xamarin Forms - Implicit Styles
This post is about implementing implicit styles, those that are automatically ... let's create an implicit style inside our ContentPage.
Read more >
Working with .NET MAUI Styles - YouTube
In this video you will learn about implicit styles, explicit styles ... in my free time, and not officially affiliated with or endorsed...
Read more >
Styles and Resources - Xamarin Forms Guide
Implicit styles do not specify a key when they are defined. The style will be applied automatically to all controls of the specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found