Issue with VisualStateManager for CollectionView in Xamarin Forms - xamarin.forms

I have issue with CollectionView and VisualStateManager.
This is my CollectionView. I've also trying to use Compiled Bindings.
<CollectionView Grid.Row="1"
ItemSizingStrategy="MeasureAllItems"
ItemsSource="{Binding SizeOptions}"
Margin="0"
SelectionChangedCommand="{Binding SelectionChangedCommand}"
SelectedItem="{Binding SelectedSizeOption}"
SelectionMode="Single">
<CollectionView.Header>
<BoxView VerticalOptions="Start"
HeightRequest="1"
Color="{StaticResource DividerColor}"/>
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="tpViewModels:SizeOption">
<StackLayout IsEnabled="{Binding IsEnabled}">
<StackLayout AutomationId="{Binding Text}"
AutomationProperties.IsInAccessibleTree="True"
HeightRequest="64"
IsEnabled="{Binding IsEnabled}"
Margin="10, 0, 0, 0"
MinimumHeightRequest="64"
Orientation="Horizontal"
Padding="0"
x:Name="Holder">
<Image HeightRequest="20"
IsEnabled="{Binding IsEnabled}"
WidthRequest="20"
x:Name="RadioButtonImage">
</Image>
<Label FontSize="14"
HorizontalOptions="StartAndExpand"
IsEnabled="{Binding IsEnabled}"
Padding="10, 0"
Text="{Binding Text}"
Style="{StaticResource MediumFontFamily}"
VerticalTextAlignment="Center"
x:Name="RadioButtonLabel">
</Label>
</StackLayout>
<BoxView VerticalOptions="Start"
HeightRequest="1"
Color="{StaticResource DividerColor}"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
When I don't use DataType in DataTemplate, then IsEnabled = false woks perfect, we cannot select item in list. But when I use DataType, then I can select diabled item.
Also I want to change TextColor, FontAttributes and Image.Source when item should be disabled.
It sets for me only VisualStates = Normal or Selected, VisualStateManager doesn't works with State = Disabled.
I've added VisualStateManager in first StackLayout with TargetName setted to x:Name of Label and Image.
DataTrigger for Label and Image works, but I can selected disabled item :(
Anyone knows why?

You could try to set the Visual State Manager to the ContentPage.Resources.
Like:
<ContentPage.Resources>
<Style TargetType="Label">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" >
<VisualState.Setters>
<Setter Property="TextColor"
Value="LightSkyBlue" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="TextColor"
Value="LightSkyBlue" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="TextColor"
Value="Green" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<Style TargetType="Image">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" >
<VisualState.Setters>
<Setter Property="Source"
Value="normalicon.png" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="Source"
Value="normalicon.png" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="Source"
Value="disableicon.png" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ContentPage.Resources>

Related

How do you change the color of TAB icons in the flyout menu of Xamarin Forms Shell when using tabs?

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>

Xamarin.Forms: how to apply a style on a Expander containing an Indicator

I would like to re use some Expanders in a Xamarin.Forms app.
The Expander uses Image as FontImageSource to display chevrons as Indicator, and the DataTrigger on the Image allows to switch between up/down chevron:
<Expander>
<Expander.Header>
<Grid>
<Label Text="Who we are?"
Style="{StaticResource AboutPageCategoryLabelStyle}" />
<Image
HeightRequest="20"
HorizontalOptions="End"
VerticalOptions="Center"
WidthRequest="20">
<Image.Source>
<FontImageSource
FontFamily="FontAwesomeLight"
Glyph="{StaticResource FalIconChevronDown}"
Size="20"
Color="Gray" />
</Image.Source>
<Image.Triggers>
<DataTrigger
Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}}, Path=IsExpanded}"
TargetType="Image"
Value="True">
<Setter Property="Source">
<Setter.Value>
<FontImageSource
FontFamily="FontAwesomeLight"
Glyph="{StaticResource FalIconChevronUp}"
Size="20"
Color="Gray" />
</Setter.Value>
</Setter>
</DataTrigger>
</Image.Triggers>
</Image>
</Grid>
</Expander.Header>
<Expander.ContentTemplate>
<DataTemplate>
...
</DataTemplate>
</Expander.ContentTemplate>
</Expander>
I've tried to create a Style to duplicate easily the same Expander, but it doesn't work:
I can define the style of the Image for the "default" indicator mode:
<Style x:Key="ChevronImageForExpander" TargetType="Image">
<Setter Property="BackgroundColor">Transparent</Setter>
<Setter Property="HorizontalOptions">End</Setter>
<Setter Property="VerticalOptions">Center</Setter>
<Setter Property="HeightRequest">20</Setter>
<Setter Property="WidthRequest">20</Setter>
<Setter Property="Source">
<Setter.Value>
<FontImageSource Glyph="{StaticResource FalIconChevronDown}"
FontFamily="FontAwesomeLight"
Size="20"
Color="{StaticResource Gray-600}"/>
</Setter.Value>
</Setter>
</Style>
Then in my View I apply this style:
<Expander>
<Expander.Header>
<Grid>
<Label Text="Header" />
<Image Style="{StaticResource ChevronImageForExpander}">
</Image>
</Grid>
</Expander.Header>
<Expander.ContentTemplate>
<DataTemplate>
<Grid>
<Label Text="Cotnent" />
</Grid>
</DataTemplate>
</Expander.ContentTemplate>
</Expander>
This works fine, but I only have the "default" indicator image.
I've tried to define the style through a Trigger for the "expanded" indicator mode:
<Style x:Key="ChevronImageForExpanderTrigger" TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}}, Path=IsExpanded}"
TargetType="Image"
Value="True">
<Setter Property="Source">
<Setter.Value>
<FontImageSource
FontFamily="FontAwesomeLight"
Glyph="{StaticResource FalIconChevronUp}"
Size="20"
Color="{StaticResource Gray-600}" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
This also works fine, but I only have the "expanded" indicator image.
So I've tried to "merge" the 2 styles like this:
<Style x:Key="ChevronImageForExpander" TargetType="Image">
<Setter Property="BackgroundColor">Transparent</Setter>
<Setter Property="HorizontalOptions">End</Setter>
<Setter Property="VerticalOptions">Center</Setter>
<Setter Property="HeightRequest">20</Setter>
<Setter Property="WidthRequest">20</Setter>
<Setter Property="Source">
<Setter.Value>
<FontImageSource Glyph="{StaticResource FalIconChevronDown}"
FontFamily="FontAwesomeLight"
Size="20"
Color="{StaticResource Gray-600}"/>
</Setter.Value>
</Setter>
<Setter Property="Triggers">
<Setter.Value>
<DataTrigger Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}}, Path=IsExpanded}"
TargetType="Image"
Value="True">
<Setter Property="Source">
<Setter.Value>
<FontImageSource
FontFamily="FontAwesomeLight"
Glyph="{StaticResource FalIconChevronUp}"
Size="20"
Color="{StaticResource Gray-600}" />
</Setter.Value>
</Setter>
</DataTrigger>
</Setter.Value>
</Setter>
</Style>
But this doesn't work and I get an Exception: "System.InvalidOperationException: The BindableProperty "Triggers" is readonly.".
I could also create a control, but I would like to use different kinds of content for the Expander.ContentTemplate: labels, images, ...
How should be the better approach to easily reuse this Expander?
Edit: add some code for the Style
Finally it was just a problem of Trigger declaration in the "global" style: we must use <Style.Triggers> instead of <Setter Property="Triggers">
So, like this it works well:
<Style x:Key="ChevronImageForExpander" TargetType="Image">
<Setter Property="BackgroundColor">Transparent</Setter>
<Setter Property="HorizontalOptions">End</Setter>
<Setter Property="VerticalOptions">Center</Setter>
<Setter Property="HeightRequest">20</Setter>
<Setter Property="WidthRequest">20</Setter>
<Setter Property="Source">
<Setter.Value>
<FontImageSource Glyph="{StaticResource FalIconChevronDown}"
FontFamily="FontAwesomeLight"
Size="20"
Color="{StaticResource Gray-600}"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}}, Path=IsExpanded}"
TargetType="Image"
Value="True">
<Setter Property="Source">
<Setter.Value>
<FontImageSource
FontFamily="FontAwesomeLight"
Glyph="{StaticResource FalIconChevronUp}"
Size="20"
Color="{StaticResource Gray-600}" />
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
And in the XAML:
<Expander>
<Expander.Header>
<Grid>
<Label Text="Header" />
<Image Style="{StaticResource ChevronImageForExpander}">
</Image>
</Grid>
</Expander.Header>
<Expander.ContentTemplate>
<DataTemplate>
<Grid>
<Label Text="Content" />
</Grid>
</DataTemplate>
</Expander.ContentTemplate>
</Expander>
Maybe is there another approach to apply ContentTemplate to the Header (both to the Label and to the Image), but at least, it's correct like this.

Xamarin.Forms CollectionView selected item has weird gray border?

I'm coding in Visual Studio Mac, using the iPhone 8 simulator running iOS 13.6.
Here's my code for my collection view:
<CollectionView
Margin="0"
VerticalScrollBarVisibility="Never"
BackgroundColor="Transparent"
x:Name="selectableItemsList"
SelectionMode="Multiple"
HorizontalOptions="Center"
VerticalOptions="Center"
SelectionChanged="selectableItemsList_SelectionChanged"
ItemsSource="{Binding Services}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Image
Source="{Binding Image}"
BackgroundColor="Transparent"
HeightRequest="100"
WidthRequest="100"
Aspect="AspectFit"
HorizontalOptions="Center"
VerticalOptions="Start">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup
Name="CommonStates">
<VisualState
Name="Normal" />
<VisualState
Name="Focused" />
<VisualState
Name="Selected">
<VisualState.Setters>
<Setter
Property="BackgroundColor"
Value="Yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Image>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Here's what the items look like when not selected:
And here's what they look like when selected:
See that grey line at the top and left side of each icon? How the heck do I get rid of that?
Is there a way to do a work-around that uses a data trigger to change the image's background color when the item is selected?
Please Note:
Moving the VisualStateManager.VisualStateGroups section into a style in a ResourceDictionary does not solve the problem.
Have a try with put the image inside a Grid:
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Image
Source="{Binding .}"
BackgroundColor="Transparent"
HeightRequest="100"
WidthRequest="100"
HorizontalOptions="Center"
VerticalOptions="Start">
</Image>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup
Name="CommonStates">
<VisualState
Name="Normal" />
<VisualState
Name="Focused" />
<VisualState
Name="Selected">
<VisualState.Setters>
<Setter
Property="BackgroundColor"
Value="Yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>

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>

Problem with Visual State Manager and Entry && firing keyboard xamarin forms

In the first part, the code I use with a grid, I have to clique 2 times on entry filed to fire the keyboard , while in second part with no grid, only from the first time and I can't understand why
<ContentPage.Content>
<Grid VerticalOptions="FillAndExpand">
<Grid.ColumnSpacing>
<OnIdiom x:TypeArguments="x:Double"
Phone="0"
Tablet="40"/>
</Grid.ColumnSpacing>
<Grid.RowSpacing>
<OnIdiom x:TypeArguments="x:Double"
Phone="20"
Tablet="20"/>
</Grid.RowSpacing>
<Grid.Padding>
<OnIdiom x:TypeArguments="Thickness"
Phone="10, 30, 10, 30"
Tablet="20, 20, 20, 0"/>
</Grid.Padding>
<Grid.RowDefinitions>
<RowDefinition Height="3*"/>
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackLayout Grid.Row="1" Grid.RowSpan="2" Grid.ColumnSpan="2">
<Entry Placeholder="Insert your code here"
HorizontalOptions="Center"
VerticalOptions="Center"
x:Name="cltCode">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="FontSize" Value="30" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</StackLayout>
</Grid>
</ContentPage.Content>
https://drive.google.com/open?id=1-1AsOckjkXrno1M7yhiq1cVdyRC0FoBU
<ContentPage.Content>
<Entry Placeholder="Insert your code here"
HorizontalOptions="Center"
VerticalOptions="Center"
x:Name="cltCode">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="FontSize" Value="30" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</ContentPage.Content>
https://drive.google.com/open?id=1-3KC3CmeisaYuthFTnPTMJ62hDE4zeeI
This is an issue in xamarin forms and here is the issue link : Focused not firing keyboard
https://github.com/xamarin/Xamarin.Forms/issues/4573

Resources