Pages

Thursday, 24 January 2019

Visual State Manager in Xamrin Forms


 Suppose in Entry view, and we want the visual appearance of the Entry to change in the following ways:
·         In normal state, Entry field should have Red background.
·         In focused state, Entry field should have Gray background with font-size 50.



<StackLayout>
<StackLayout.Resources>
<Style TargetType="Entry">
<Setter Property="Margin" Value="20, 10" />
<Setter Property="FontSize" Value="22" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup>

<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Red" />
</VisualState.Setters>
</VisualState>

<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="FontSize" Value="50" />
<Setter Property="BackgroundColor" Value="Gray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</StackLayout.Resources>

<Label Text="Entry:" Margin="25, 35, 25, 10" FontSize="Medium"/>

<Entry />
</StackLayout>


No comments:

Post a Comment