I've defined the following explicit style in App.xaml
:
<Application.Resources>
<ResourceDictionary>
<Style TargetType="ContentPage" x:Key="PageStyle">
<Setter Property="BackgroundColor" Value="#ff0000" />
</Style>
</ResourceDictionary>
</Application.Resources>
The page, which I want to show, is embedded into a NavigationPage
and has derived from ContentPage
. It has the following implicit style, whereas here ContentPage
instead of my derived type is used (in real I use the derived type, but I tried it without and I had the same effect):
<ContentPage.Resources>
<ResourceDictionary>
<Style TargetType="ContentPage" BasedOn="{StaticResource PageStyle}" />
</ResourceDictionary>
</ContentPage.Resources>
But the background of the page doesn't change. It always shows the default background color of the platform. If I use a style for a Button
, the style is applied. I tried it with NavigationPage
, ContentPage
, Page
, VisualElement
, but the background is always the default background.
If I explicitly set the color with
<ContentPage.BackgroundColor>
<Color>Red</Color>
</ContentPage.BackgroundColor>
or
this.BackgroundColor = Color.Red;
the color is applied.
You can assign it globally, you have to set ApplyToDerivedTypes
to true. Here is an example:
<Style TargetType="ContentPage" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="#4A4A4A" />
</Style>
Now all classes that inherit ContentPage will have this background color.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With