Im set style in App.xaml
<Style x:Key="ContentPageStyle" TargetType="ContentPage"> <Setter Property="BackgroundColor" Value="{AppThemeBinding Light=#FFFFFF, Dark=#020202}" /></Style>
This style applying only case if set Style
property for ContentPage
element
<views:BasicView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:views="clr-namespace:SkeletonApp.View.Page;assembly=SkeletonApp" x:Class="SkeletonApp.Example.MainPage" Style="{StaticResource ContentPageStyle}" Title="Home"><!-- Content markup --></views:BasicView>
How can i do auto-applying styles when i set TargetType
? It's truly possible?
And why style doesn't apply if i set Style
property in parent class by next code
CS-file:
namespace SkeletonApp.View.Page{ public partial class BasicView : ContentPage { public BasicView() { } }}
Markup-file:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SkeletonApp.View.Page.BasicView" Style="{StaticResource ContentPageStyle}"></ContentPage>
UPD (full file App.xaml):
<?xml version="1.0" encoding="utf-8" ?><Application x:Class="SkeletonApp.App" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"><Application.Resources><Color x:Key="TransparentColor">Transparent</Color><!-- Light colors --><Color x:Key="LightPageBackgroundColor">Magenta</Color><!-- Dark colors --><Color x:Key="DarkPageBackgroundColor">Lime</Color><Style x:Key="ContentPageStyle" TargetType="ContentPage" ApplyToDerivedTypes = "True"> <Setter Property="BackgroundColor" Value="{AppThemeBinding Light={StaticResource LightPageBackgroundColor}, Dark={StaticResource DarkPageBackgroundColor}}" /></Style></Application.Resources></Application>