如何放大活动的输入字段。活动 - 按
后将触发此地点激活的地方
答案 0 :(得分:0)
查看适用于Xamarin Forms 3.0的新Visual State Manager
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual-state-manager
它允许您为不同的状态设置样式。常见状态为Normal
,Focused
,Disabled
。
你可以,例如增加FontSize
并与其他州做同样的事情。 (看一下给定的链接)
您想要的状态是Focused
。
<Entry FontSize="18">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Lime" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="FontSize" Value="36" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Pink" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
答案 1 :(得分:0)
您可以使用Scale方法来增加Entry的大小。每个视图都有可用于增加大小的属性Scale;
entry.Scale =2;
答案 2 :(得分:0)
有很多方法可以实现这一目标。
其中一个是改变位置属性,如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);
}
你会得到类似的东西: