Xamarin, Button bug while using transparent background [Image] - button

As you can see, button has an unexpected behavior when is pressed on Android!
<Button
HorizontalOptions="FillAndExpand"
Text="English"
Clicked="English_OnClicked"
Style="{StaticResource wizardButton}"/>
App.Xml:
<Style x:Key="wizardButton" TargetType="Button" BasedOn="{StaticResource buttonStyle}">
<Setter Property="BackgroundColor" Value="#3FFF" />
<Setter Property="BorderColor" Value="#FFFF" />
<Setter Property="TextColor" Value="#CFFF" />
<Setter Property="BorderWidth" Value="2" />
</Style>
<Style x:Key="buttonStyle" TargetType="Button">
<Setter Property="TextColor" Value="White" />
<Setter Property="BorderRadius" Value="4" />
<Setter Property="FontSize" Value="Medium" />
<Setter Property="BackgroundColor" Value="{StaticResource grayDark}" />
<Setter Property="HeightRequest">
<Setter.Value>
<OnPlatform x:TypeArguments="x:Double" iOS="40" Android="50" />
</Setter.Value>
</Setter>
</Style>
Also I checked it on real devices and same result!
Xamarin.Forms: 2.3.4.267
The Build Target is 7.1

Related

Xamarin Forms LinearGradientBrush of Frame not working when colors are set from Dynamic Style

I am trying to use a Style to create a Frame with a linear gradient in it. If I hard code the colors in the style, the Frame shows correctly. If I attempt to bind the colors to properties in my custom app setting object, the style does not work. Below is an example:
Here is the static style. I configured it to use the same colors coming from the object to ensure there was nothing wrong with the values.
<Style x:Key="wlHeaderGradient" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="#FF008080" Offset="0.0" />
<GradientStop Color="#FFFF6347" Offset="0.5" />
<GradientStop Color="#FF008080" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
Here is the Dynamic Style
<Style x:Key="wlHeaderGradient1" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor1.ColorHex}" Offset="0.0" />
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor2.ColorHex}" Offset="0.5" />
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor1.ColorHex}" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
Here is the StackLayout I am using to test this:
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Start">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Start">
<Frame x:Name="frmTest" Style="{StaticResource wlHeaderGradient}">
</Frame>
<Frame x:Name="frmTest1" Style="{StaticResource wlHeaderGradient1}">
</Frame>
</StackLayout>
<Label x:Name="lblBGColor1" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="lblBGColor2" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="lblSampleWithStyle" Style="{StaticResource wlPublicHeader1}" Text="This is a working style with binding to same object." />
</StackLayout>
Here is the code from the CodeBehind page were I display the CheckInHeaderBgColor1 and CheckInHeaderBgColor2 values. I run this code at the end of the OnAppearing event:
lblBGColor1.Text = App.gvm_AppSettings.HostPublicStyleInfo.CheckInHeaderBgColor1.ColorHex;
lblBGColor2.Text = App.gvm_AppSettings.HostPublicStyleInfo.CheckInHeaderBgColor2.ColorHex;
Here is the output I get:
I bind the entire page to my appseting in the CodeBehind as follows:
this.BindingContext = App.gvm_AppSettings;
NOTE: I use other properties from this AppSettings object in other styles on the page (as shown below) and they seem to work. In the screen shot, you can see the text color of the last label matches the background color of the screen below it.
Here is the style:
<Style x:Key="wlPublicHeader1" TargetType="Label" >
<Setter Property="BackgroundColor" Value="Transparent" />
<Setter Property="Padding" Value="8,4,8,4" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="{Binding HostPublicStyleInfo.CheckInFormBgColor1.ColorHex}" />
<Setter Property="FontSize" Value="Small" />
<Setter Property="FontAttributes" Value="Bold" />
</Style>
If anyone has an idea of what I am doing wrong I would greatly appreciate the feedback.
UPDATE::
Based on feedback below - I created a property of my custom color object that returned a Xamarin.Forms.Color object and attempted to bind to that property. It did not work. I also tried using dynamic properties in the App.Xaml file, modifying the value of those properties when my custom color object is loaded but that did not work either. Here are the updated samples:
App.Xaml Colors
<Application.Resources>
<ResourceDictionary>
<Color x:Key="grdHeaderBGColor1">White</Color>
<Color x:Key="grdHeaderBGColor2">Black</Color>
Here are the three updated test styles:
<Style x:Key="wlHeaderGradient" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="#FF008080" Offset="0.0" />
<GradientStop Color="#FFFF6347" Offset="0.5" />
<GradientStop Color="#FF008080" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
<Style x:Key="wlHeaderGradient1" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor1.DisplayColor}" Offset="0.0" />
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor2.DisplayColor}" Offset="0.5" />
<GradientStop Color="{Binding HostPublicStyleInfo.CheckInHeaderBgColor1.DisplayColor}" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
<Style x:Key="wlHeaderGradient2" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
</Style>
And here is the XAML to generate the sample Frames and Example 2 uses the Dynamic Resources.
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Start">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Start">
<Frame x:Name="frmTest" Style="{StaticResource wlHeaderGradient}">
</Frame>
<Frame x:Name="frmTest1" Style="{StaticResource wlHeaderGradient1}">
</Frame>
<Frame x:Name="frmTest2" Style="{StaticResource wlHeaderGradient2}">
<Frame.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="0.0" />
<GradientStop Color="{DynamicResource grdHeaderBGColor2}" Offset="0.5" />
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="1.0" />
</LinearGradientBrush>
</Frame.Background>
</Frame>
</StackLayout>
<Label x:Name="lblBGColor1" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="lblBGColor2" HorizontalOptions="Center" VerticalOptions="Center"/>
<Label x:Name="lblSampleWithStyle" Style="{StaticResource wlPublicHeader1}" Text="This is a working style with binding to same object." />
</StackLayout>
The results are as follows:
The second sample - binding to a Xamarin.Forms.Color object does not work at all. The third example, attempting to use the dynamic resources never updates to the new colors (they stay the static black and white values) even though I have ensured the values are being changed when the custom color objects are being loaded.
So again I am at a loss here.
The second sample - binding to a Xamarin.Forms.Color object does not work at all.
The second question is need to set Path to a sub-property to do the binding.
Set the Name of the page.
x:Name="root"
Style with binding:
<Style x:Key="wlHeaderGradient1" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{Binding Path = BindingContext.CheckInHeaderBgColor1 ,Source={x:Reference root}}" Offset="0.0" />
<GradientStop Color="{Binding Path = BindingContext.CheckInHeaderBgColor2 ,Source={x:Reference root}}" Offset="0.5" />
<GradientStop Color="{Binding Path = BindingContext.CheckInHeaderBgColor1 ,Source={x:Reference root}}" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
Xaml:
<StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Start">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Start">
<Frame Style="{StaticResource wlHeaderGradient1}" x:Name="frmTest1" >
</Frame>
</StackLayout>
</StackLayout>
Code behind:
public Page12()
{
InitializeComponent();
this.BindingContext = new HostPublicStyleInfo();
}
ViewModel:
public class HostPublicStyleInfo
{
public HostPublicStyleInfo()
{
CheckInHeaderBgColor1 = "#FF008080";
CheckInHeaderBgColor2 = "#FFFF6347";
frmTest2Style = "frmTest2GradientStyle";
}
public string frmTest2Style { get; set; }
public string CheckInHeaderBgColor1 { get; set; }
public string CheckInHeaderBgColor2 { get; set; }
}
The third example, attempting to use the dynamic resources never updates to the new colors (they stay the static black and white values) even though I have ensured the values are being changed when the custom color objects are being loaded.
Set the White-Black-White in Style instead of in Frame.
<Style x:Key="wlHeaderGradient2" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="0.0" />
<GradientStop Color="{DynamicResource grdHeaderBGColor2}" Offset="0.5" />
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>
And then you could cover it with the new style. frmTest2GradientStyle is the style which i set in Application.Resources.
frmTest2.Style = (Style)Application.Current.Resources["frmTest2GradientStyle"];
If you set the background in Frame like below, you could change the background instead of Background.
<Frame x:Name="frmTest3" Style="{StaticResource wlHeaderGradient2}">
<Frame.Background>
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="0.0" />
<GradientStop Color="{DynamicResource grdHeaderBGColor2}" Offset="0.5" />
<GradientStop Color="{DynamicResource grdHeaderBGColor1}" Offset="1.0" />
</LinearGradientBrush>
</Frame.Background>
</Frame>
Change the background in code:
GradientStopCollection gradientStops = new GradientStopCollection();
gradientStops.Add(new GradientStop() { Color = Color.Green, Offset = (float)0.0 });
gradientStops.Add(new GradientStop() { Color = Color.Red, Offset = (float)0.5 });
gradientStops.Add(new GradientStop() { Color = Color.Green, Offset = (float)1.0 });
LinearGradientBrush linearGradientBrush = new LinearGradientBrush()
{
EndPoint = new Point(0, 1),
GradientStops = gradientStops
};
frmTest3.Background = linearGradientBrush;
In my experience, I have found colors not binding properly when you try to bind them to string hex values like this. You could change the type of those string fields to color object and try.
Is your CheckInHeaderBgColor1 and CheckInHeaderBgColor2 properties of the type Color? If yes, try binding them directly
Dynamic colors will also work. Like this:
<Style x:Key="wlHeaderGradient" TargetType="Frame">
<Setter Property="BorderColor" Value="Purple" />
<Setter Property="HasShadow" Value="False" />
<Setter Property="CornerRadius" Value="0" />
<Setter Property="HeightRequest" Value="100" />
<Setter Property="WidthRequest" Value="100"/>
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="Background">
<LinearGradientBrush EndPoint="0,1">
<GradientStop Color="{DyanmicResource Color1}" Offset="0.0" />
<GradientStop Color="{DyanmicResource Color2}" Offset="0.5" />
<GradientStop Color="{DyanmicResource Color3}" Offset="1.0" />
</LinearGradientBrush>
</Setter>
</Style>

Device differences Xaml setting on Idiom

I need to used OnIdiom, I am setting width and height to button however if I display the button on tablet and on phone it is the same. Can you please advise what am I doing wrong?
<Button
x:Name="ScanButton" Padding="0"
VerticalOptions="End" HorizontalOptions="CenterAndExpand">
<Button.Style>
<OnIdiom x:TypeArguments="Style" Tablet="{StaticResource PrimaryButtonStyleTablet}" Phone="{StaticResource PrimaryButtonStylePhone}"></OnIdiom>
</Button.Style>
</Button>
<Style x:Key="PrimaryButtonStylePhone" TargetType="Button">
<Setter Property="BackgroundColor" Value="{DynamicResource ButtonColor}" />
<Setter Property="TextColor" Value="{DynamicResource PrimaryTintColor}" />
<Setter Property="FontSize" Value="20" />
<Setter Property="CornerRadius" Value="25"/>
<Setter Property="WidthRequest" Value="200"/>
<Setter Property="HeightRequest" Value="33"/>
</Style>
<Style x:Key="PrimaryButtonStyleTablet" TargetType="Button">
<Setter Property="BackgroundColor" Value="{DynamicResource ButtonColor}" />
<Setter Property="TextColor" Value="{DynamicResource PrimaryTintColor}" />
<Setter Property="FontSize" Value="20" />
<Setter Property="CornerRadius" Value="25"/>
<Setter Property="WidthRequest" Value="390"/>
<Setter Property="HeightRequest" Value="33"/>
</Style>
You need to use the OnIdiom inside the Setter.Value.
For example, modify code of Style as follows:
<Style x:Key="PrimaryButtonStyle"
TargetType="Button">
<Setter Property="BackgroundColor">
<Setter.Value>
<OnIdiom Phone="{DynamicResource phoneDynamicResource}"
Tablet="{DynamicResource tableDynamicResource}"/>
</Setter.Value>
</Setter>
<Setter Property="TextColor">
<Setter.Value>
<OnIdiom Phone="Blue" Tablet="Green"/>
</Setter.Value>
</Setter>
<Setter Property="FontSize">
<Setter.Value>
<OnIdiom Phone="20" Tablet="20"/>
</Setter.Value>
</Setter>
<Setter Property="CornerRadius">
<Setter.Value>
<OnIdiom Phone="25" Tablet="25" />
</Setter.Value>
</Setter>
<Setter Property="WidthRequest">
<Setter.Value>
<OnIdiom Phone="200" Tablet="390" />
</Setter.Value>
</Setter>
<Setter Property="HeightRequest">
<Setter.Value>
<OnIdiom Phone="33" Tablet="33" />
</Setter.Value>
</Setter>
</Style>
And used for Button:
<Button x:Name="ScanButton"
Padding="0"
VerticalOptions="End"
Text="Button"
Style="{StaticResource PrimaryButtonStyle}"
HorizontalOptions="CenterAndExpand">
</Button>

Xamarin Form 4 Shell

I start an new projet with the new Shell from Xamarin Form 4. I try to found a way to control the appearance when a FlyoutItem is disable. On the style with the sample, the BaseStyle control the apparence of the Shell himself (title bar tab bar, ...) But the Shell.disableColor is for the shell himself not the flyoutItem text. Any idea?
<Shell.Resources>
<ResourceDictionary>
<Color x:Key="NavigationPrimary">#2196F3</Color>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource NavigationPrimary}" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.TitleColor" Value="White" />
<Setter Property="Shell.DisabledColor" Value="#95FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource NavigationPrimary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
</Style>
<Style x:Key="FAIcon" TargetType="Label">
<Setter Property="VerticalTextAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{StaticResource FARegular}"/>
<Setter Property="FontSize" Value="{StaticResource BigSize}"/>
<Setter Property="TextColor" Value="#FF000000"/>
</Style>
<Style x:Key="ItemText" TargetType="Label">
<Setter Property="VerticalTextAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{StaticResource SourceSansProRegular}"/>
<Setter Property="FontSize" Value="{StaticResource BigSize}"/>
<Setter Property="TextColor" Value="#FF000000"/>
</Style>
</ResourceDictionary>
</Shell.Resources>
<Shell.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.8*" />
</Grid.ColumnDefinitions>
<Label Margin="15,0,0,0" Text="{Binding FlyoutIcon}" Style="{StaticResource FAIcon}" />
<Label Grid.Column="1"
Text="{Binding Title}"
Style="{StaticResource ItemText}"/>
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
<Shell.FlyoutHeader>
<Grid HeightRequest="180" BackgroundColor="{StaticResource DarkGreyColor}">
<Image Source="KelvinSplash1.png"
Aspect="AspectFill"
HeightRequest="180"
HorizontalOptions="FillAndExpand" />
<Label Text="Kelvin Mobile"
TextColor="White"
FontSize="32"
HorizontalOptions="Center"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</Grid>
</Shell.FlyoutHeader>
<FlyoutItem Icon=""
Title="Accueil">
<ShellContent Route="Home" ContentTemplate="{DataTemplate views:HomePage}" />
</FlyoutItem>
<FlyoutItem Icon=""
Title="Division: Solmec" IsEnabled="false">
</FlyoutItem>
<FlyoutItem Icon=""
Title="Fonctions">
</FlyoutItem>
<FlyoutItem Icon=""
Title="À Propos"
IsEnabled="False">
<ShellContent Route="About" ContentTemplate="{DataTemplate views:AboutPage}" />
</FlyoutItem>

Global Styles not working in iOS

I posted this in the Xamarin Forums but there have been no replies.
I have the following global styles defined in app.xaml and applied on a content page (see attached). This works as expected in Android and UWP, but doesn't work in iOS. In Android and UWP the background is dark grey with a padding of 20. In iOS the background is white with no padding. None of the styles work at all in iOS, but the colors defined at the top do work in all platforms.
app.xaml
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Rhyme4RhymeApp.App">
<Application.Resources>
<ResourceDictionary>
<Color x:Key="backgroundColor">#3F3F3F</Color>
<Color x:Key="navBackgroundColor">#232323</Color>
<Color x:Key="textColor">#ffffff</Color>
<Color x:Key="textColorAccent">#191919</Color>
<Color x:Key="imageBackgroundColor">#191919</Color>
<Color x:Key="DarkGrey">#191919</Color>
<Color x:Key="Grey">#3F3F3F</Color>
<Color x:Key="LightGrey">#6a6a6a</Color>
<Color x:Key="White">#ffffff</Color>
<Color x:Key="Orange">#f77e4f</Color>
<Style x:Key="pageStyle" TargetType="Page" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="#3F3F3F" />
<Setter Property="Padding" Value="20" />
</Style>
<Style x:Key="NavStyle" TargetType="Page">
<Setter Property="BackgroundColor" Value="#383838" />
<Setter Property="Padding" Value="20" />
</Style>
<Style x:Key="semiTransparentColor" TargetType="Layout">
<Setter Property="BackgroundColor" Value="#000000" />
<Setter Property="Opacity" Value=".9"/>
</Style>
<Style x:Key="masterDetailMenuStyle" TargetType="Page">
<Setter Property="BackgroundColor" Value="#3F3F3F" />
</Style>
<Style x:Key="buttonStyle" TargetType="Button" ApplyToDerivedTypes="True">
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="BorderColor" Value="#191919" />
<Setter Property="BorderRadius" Value="0" />
<Setter Property="BorderWidth" Value="1" />
<Setter Property="TextColor" Value="#191919" />
<Setter Property="BackgroundColor" Value="#ffffff" />
</Style>
<Style x:Key="linkStyle" TargetType="Label">
<Setter Property="TextColor" Value="#f77e4f" />
</Style>
<Style x:Key="Header1LabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="28" />
<Setter Property="FontAttributes" Value="Bold"/>
</Style>
<Style x:Key="Header2LabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="24" />
</Style>
<Style x:Key="Header3LabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="20" />
<Setter Property="FontAttributes" Value="Bold"/>
</Style>
<Style x:Key="Header4LabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="20" />
</Style>
<Style x:Key="quoteLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="28" />
<Setter Property="FontAttributes" Value="Italic"/>
</Style>
<Style x:Key="albumLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="23" />
<Setter Property="FontAttributes" Value="Bold"/>
</Style>
<Style x:Key="artistLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontAttributes" Value="Bold"/>
</Style>
<Style x:Key="standardLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="#ffffff" />
<Setter Property="FontSize" Value="14" />
</Style>
<Style x:Key="imageBackground" TargetType="Image">
<Setter Property="BackgroundColor" Value="#afafaf" />
</Style>
<Style x:Key="artistListItem" TargetType="TextCell">
<Setter Property="TextColor" Value="#ffffff"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Content Page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Rhyme4RhymeApp.NewQuotesPage" Style="{DynamicResource pageStyle}">
<ContentPage.Content>
<StackLayout x:Name="mainStack">
<ActivityIndicator x:Name="loader" Color="{DynamicResource White}" IsEnabled="True" IsVisible="True" IsRunning="True" />
<Label x:Name="lblAddedHeader" FontSize="Large" FontAttributes="Bold" TextColor="{DynamicResource White}" />
<Label x:Name="lblNoResults" Text="" FontSize="Default" FontAttributes="Bold" TextColor="{DynamicResource White}" IsVisible="False" />
<ListView x:Name="QuotesListView" AutomationId="WhatsNewLVQuotes" HorizontalOptions="FillAndExpand" CachingStrategy="RecycleElement" BackgroundColor="{DynamicResource Grey}"></ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Replace your XAML code with this please:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Rhyme4RhymeApp.NewQuotesPage" Style="{StaticResource pageStyle}">
<ContentPage.Content>
<StackLayout x:Name="mainStack">
<ActivityIndicator x:Name="loader" Color="{StaticResource textColor}" IsEnabled="True" IsVisible="True" IsRunning="True" />
<Label x:Name="lblAddedHeader" FontSize="Large" FontAttributes="Bold" TextColor="{StaticResource textColor}" />
<Label x:Name="lblNoResults" Text="" FontSize="Default" FontAttributes="Bold" TextColor="{StaticResource textColor}" IsVisible="False" />
<ListView x:Name="QuotesListView" AutomationId="WhatsNewLVQuotes" HorizontalOptions="FillAndExpand" CachingStrategy="RecycleElement" BackgroundColor="{StaticResource backgroundColor}"></ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage>

Xamarin Forms build error - StaticResource not found for key

I'm just learning XAML and Xamrin. I'm trying to learn how static styles work. Here's my XAML code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Styles"
x:Class="Styles.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<Style x:key="buttonStyle" TargetType="Button">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="Red"/>
<Setter Property="FontSize" Value="Small"/>
</Style>
<Style TargetType="Label">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="Blue"/>
<Setter Property="FontSize" Value="20"/>
</Style>
<Style x:key="baseStyle" TargetType="View">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
</Style>
<Style x:key="entryStyle" TargetType="Entry" BasedOn="{StaticResource baseStyle}">
<Setter Property="TextColor" Value="Green"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Padding="20">
<Label Text="This is label 1 using implicit style"/>
<Label Text="This is label 2"/>
<Button
Text="Not using the button style"
BorderWidth="2"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="200"/>
<Button Style="{StaticResource buttonStyle}"
Text="Using explicit style"
BorderWidth="2"
WidthRequest="200"/>
<Entry Style="{StaticResource entryStyle}" Placeholder="This enty uses an inherited style"/>
<Button Style="{StaticResource buttonStyle}"
Text="Using explicit style"
BorderWidth="2"
WidthRequest="200"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Compile works fine, but when running, I get this exception:
[ERROR] FATAL UNHANDLED EXCEPTION: Xamarin.Forms.Xaml.XamlParseException: Position 25:58. StaticResource not found for key baseStyle
I don't understand why I get this error since the style 'key' is already defined on the previous line. Any help is greatly appreciated.
The x:Key attribute must have the first letter in uppercase.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Styles"
x:Class="Styles.MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="buttonStyle" TargetType="Button">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="Red"/>
<Setter Property="FontSize" Value="Small"/>
</Style>
<Style TargetType="Label">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="Blue"/>
<Setter Property="FontSize" Value="20"/>
</Style>
<Style x:Key="baseStyle" TargetType="View">
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center" />
</Style>
<Style x:Key="entryStyle" TargetType="Entry" BasedOn="{StaticResource baseStyle}">
<Setter Property="TextColor" Value="Green"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout Padding="20">
<Label Text="This is label 1 using implicit style"/>
<Label Text="This is label 2"/>
<Button
Text="Not using the button style"
BorderWidth="2"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="200"/>
<Button Style="{StaticResource buttonStyle}"
Text="Using explicit style"
BorderWidth="2"
WidthRequest="200"/>
<Entry Style="{StaticResource entryStyle}" Placeholder="This enty uses an inherited style"/>
<Button Style="{StaticResource buttonStyle}"
Text="Using explicit style"
BorderWidth="2"
WidthRequest="200"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>

Resources