【发布时间】:2018-08-01 08:30:06
【问题描述】:
我有一个 Xamarin Forms 项目 (v2.5),我的 Xaml 文件中有一个文本条目控件。我需要条目比默认值高,所以我指定一个 60 的 HeightRequest,它工作正常,除了文本本身与条目控件的顶部对齐。
<Entry Text="{Binding CustomerNameText}" HeightRequest="60" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" IsEnabled="{Binding CustomerNameEntryEnabled}" Focused="Entry_Focused" Unfocused="Entry_Unfocused" />
看起来像:
我添加了一个自定义渲染器:
public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if(this.Control != null)
{
this.Control.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
this.Control.Height = 60;
}
}
}
但这不起作用。 Xaml 中的 HeightRequest 似乎不再起作用,所以我在自定义渲染器中添加了高度。但文本对齐保持在顶部。
谁能告诉我如何让文本垂直居中?
【问题讨论】:
-
嗨@aritchie你有解决办法吗?
标签: xaml xamarin xamarin.forms uwp