Есть много способов достичь этого.
Один из них - изменение позиционных свойств, например Margin
:
<ContentPage.Resources>
<ResourceDictionary>
<Style TargetType="Entry">
<Style.Setters>
<Setter Property="Margin" Value="20,30,30,30"/>
<Setter Property="HorizontalOptions" Value="FillAndExpand"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="BackgroundColor" Value="AliceBlue"/>
</Style.Setters>
</Style>
<Style TargetType="Image">
<Style.Setters>
<Setter Property="HorizontalOptions" Value="Center"/>
<Setter Property="VerticalOptions" Value="Center"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="Source" Value="icon"/>
</Style.Setters>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
<Grid BackgroundColor="Silver">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Grid.Row="0"/>
<Entry Grid.Column="1" Grid.Row="0"
x:Name="txtName"
Placeholder="Name"
Focused="GrowEntry"
Unfocused="ShrinkEntry"/>
<Image Grid.Column="0" Grid.Row="1"/>
<Entry Grid.Column="1" Grid.Row="1"
x:Name="txtEmail"
Placeholder="E-mail"
BackgroundColor="AliceBlue"
Focused="GrowEntry"
Unfocused="ShrinkEntry"/>
<Image Grid.Column="0" Grid.Row="2"/>
<Entry Grid.Column="1" Grid.Row="2"
x:Name="txtPassword"
Placeholder="Password"
Focused="GrowEntry"
Unfocused="ShrinkEntry"/>
</Grid>
<BoxView Color="White"
VerticalOptions="FillAndExpand"/>
</StackLayout>
И в коде позади, GrowEntry
и ShrinkEntry
:
private void GrowEntry(object sender, EventArgs args)
{
var entry = (Entry)sender;
entry.Margin = new Thickness(6, 12, 12, 12);
}
private void ShrinkEntry(object sender, EventArgs args)
{
var entry = (Entry)sender;
entry.Margin = new Thickness(20, 30, 30, 30);
}
Вы получите что-то вроде этого: