I have created a tabbed project, with the horizontal menu created by default, but having more tabs the "More" button is created automatically, I would like to delete it and insert the scroll property.`
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:GET_SOUND.Views"
Title="GET_SOUND"
x:Class="GET_SOUND.AppShell">
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.ForegroundColor" Value="White" />
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF" />
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF" />
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}" />
<Setter Property="Shell.TabBarForegroundColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="Orange"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
<TabBar>
<ShellContent Title="DASHBOARD" x:Name="Dashboard" Icon="dashboard" Route="Dashboard" ContentTemplate="{DataTemplate local:Dashboard}" />
<ShellContent Title="MARCHI" x:Name="Marchi" Icon="marchi" Route="Marchi" ContentTemplate="{DataTemplate local:Marchi}" />
<ShellContent Title="ISRC" x:Name="Isrc" Icon="matrici" Route="Isrc" ContentTemplate="{DataTemplate local:Isrc}" />
<ShellContent Title="DOCUMENTI" x:Name="Documenti" Icon="documenti" Route="Documenti" ContentTemplate="{DataTemplate local:Documenti}" />
<ShellContent Title="IMPOSTAZIONI" x:Name="Impostazioni" Icon="imp" Route="Impostazioni" ContentTemplate="{DataTemplate local:Impostazioni}" />
<ShellContent Title="ANAGRAFICA" x:Name="Anagrafica" Icon="anagrafica" Route="Anagrafica" ContentTemplate="{DataTemplate local:Anagrafica}" />
<ShellContent Title="OPERE TUTELATE" x:Name="Opere" Icon="opere" Route="OpereTutelate" ContentTemplate="{DataTemplate local:OpereTutelate}" />
</TabBar>
Related
I'm using Xamarin Forms Shell. How can you change the color of icons in the flyout menu when using tabs?
For example I'm using a png of a black icon as my tab icon.
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<Tab Icon="pie_chart.png"
Title="Daily Target">
<ShellContent Route="TargetDataPage" ContentTemplate="{DataTemplate targetDataPageView:TargetDataPageView}" />
</Tab>
...
</FlyoutItem>
Setting the Shell TabBarTitleColor value changes the color of the black png to white in the tabs. (Which is good)
<Shell.Resources>
<ResourceDictionary>
<Style x:Key="BaseStyle" TargetType="Element">
...
<Setter Property="Shell.TabBarTitleColor" Value="White"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}" />
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}" />
</ResourceDictionary>
</Shell.Resources>
Is there a setter to set the color of the icon in the flyout menu? I need to set this because black is no good in dark mode, but I can't swap the icon for a white png icon because it's then the wrong color in light mode.
If there isn't a specific setter for flyout menu icon color, how else can I set the color? Bearing in mind the icon is set in the tab.
1.Create a custom flyout with an additional IconGlyphProperty in folder Controls
namespace Xaminals.Controls
{
public class FlyoutItemIconFont: FlyoutItem
{
public static readonly BindableProperty IconGlyphProperty = BindableProperty.Create(nameof(IconGlyphProperty), typeof(string), typeof(FlyoutItemIconFont), string.Empty);
public string IconGlyph
{
get { return (string)GetValue(IconGlyphProperty); }
set { SetValue(IconGlyphProperty, value); }
}
}
}
2.Create a FlyoutItemTemplate with two Lables and VisualStateManager:
<Shell.ItemTemplate>
<DataTemplate>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="White" />
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="White" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.8*" />
</Grid.ColumnDefinitions>
<Label x:Name="FlyoutItemIcon"
FontFamily="MaterialDesignFont"
Text="{Binding IconGlyph}"
TextColor="{Binding Source={x:Reference FlyoutItemLabel} ,Path=TextColor}"
FontSize="30"
Margin="5"/>
<Label x:Name="FlyoutItemLabel"
Grid.Column="1"
Text="{Binding Title}"
VerticalTextAlignment="Center" />
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
3.Replace the original FlyoutItem in AppShell.xaml with the custom FlyoutItem
<controls:FlyoutItemIconFont Title="About" IconGlyph="{StaticResource IconInfo}">
<ShellContent Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
</controls:FlyoutItemIconFont>
<controls:FlyoutItemIconFont Title="Browse" IconGlyph="{StaticResource IconListBulleted}">
<ShellContent Route="ItemsPage" ContentTemplate="{DataTemplate local:ItemsPage}" />
</controls:FlyoutItemIconFont>
4.And add the BaseStyle to the customFlyouItem
<!--other style-->
<x:String x:Key="IconInfo"></x:String>
<x:String x:Key="IconListBulleted"></x:String>
<Style TargetType="controls:FlyoutItemIconFont" BasedOn="{StaticResource BaseStyle}"/>
Result
Refer to this - Xamarin Forms: How Can I Change the FlyoutItem.Icon's Color When It Is Selected/Deselected?
Followed the case i done before with the Material Design Icons.
Xamarin Forms: How Can I Change the FlyoutItem.Icon's Color When It Is Selected/Deselected?
<Shell.Resources>
<ResourceDictionary>
<Color x:Key="fgColor">#66169C</Color>
<Color x:Key="bgColor">#FFFFFF</Color>
<Color x:Key="OverDueItem">#FF1C07</Color>
<OnPlatform x:Key="Material" x:TypeArguments="x:String">
<On Platform="iOS" Value="Material Design Icons" />
<On Platform="Android" Value="materialdesignicons-webfont.ttf#Material Design Icons" />
</OnPlatform>
<Style x:Key="MaterialIcons" TargetType="{x:Type Label}">
<Setter Property="FontFamily" Value="{DynamicResource Material}" />
<Setter Property="FontSize" Value="100" />
<Setter Property="HorizontalOptions" Value="Center" />
<Setter Property="VerticalOptions" Value="Center" />
<Setter Property="TextColor" Value="{DynamicResource fgColor}" />
<Setter Property="FontSize" Value="Large" />
</Style>
<Style x:Key="FloutItemStyle" TargetType="Grid">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Accent" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ResourceDictionary>
</Shell.Resources>
When you use the tab inside FlyoutItem, you could set the Material Design Icons using FontImageSource.
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems" >
<Tab Title="Page1" >
<Tab.FlyoutIcon>
<FontImageSource FontFamily="{StaticResource Material}" Color="{DynamicResource fgColor}" Glyph="">
</FontImageSource>
</Tab.FlyoutIcon>
<Tab.Icon>
<FontImageSource FontFamily="{StaticResource Material}" Color="{DynamicResource fgColor}" Glyph="" >
</FontImageSource>
</Tab.Icon>
<ShellContent Route="Page1" ContentTemplate="{DataTemplate local:Page1}" />
</Tab>
<Tab Title="Page2">
<Tab.FlyoutIcon>
<FontImageSource FontFamily="{StaticResource Material}" Color="{DynamicResource fgColor}" Glyph="">
</FontImageSource>
</Tab.FlyoutIcon>
<Tab.Icon>
<FontImageSource FontFamily="{StaticResource Material}" Color="{DynamicResource fgColor}" Glyph="" >
</FontImageSource>
</Tab.Icon>
<ShellContent Route="Page2" ContentTemplate="{DataTemplate local:Page2}"/>
</Tab>
</FlyoutItem>
Change the ItemTemplate of the FlyoutItem. Use the Label to set the Material Design Icons instead of Image. You could change the color when you select via Triggers to change the TextColor.
<Shell.ItemTemplate>
<DataTemplate>
<Grid x:Name="grid" Style="{StaticResource FloutItemStyle}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*" />
<ColumnDefinition Width="0.8*" />
</Grid.ColumnDefinitions>
<Label Style="{StaticResource MaterialIcons}" Text="{Binding FlyoutIcon.Glyph}"
Margin="5"
HeightRequest="45">
<Label.Triggers>
<DataTrigger
Binding="{Binding Source={x:Reference grid}, Path=BackgroundColor}"
TargetType="Label" Value="Accent">
<Setter Property="TextColor" Value="White" />
</DataTrigger>
</Label.Triggers>
</Label>
<Label Grid.Column="1"
Text="{Binding Title}"
FontAttributes="Italic"
VerticalTextAlignment="Center" />
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
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>
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>
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>
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>