Xamarin表单中的占位符文本对齐 [英] Placeholder text alignment in Xamarin forms
本文介绍了Xamarin表单中的占位符文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何在输入框中放置占位符文本. 我有一个很大的输入框,希望将占位符文本放在顶部.
I don't know how to top the placeholder text in a entry box. I have a entry box that is very big and want to put the placeholder text in the top.
<Entry Placeholder="Enter notes about the item"
Keyboard="Text" VerticalOptions="Start" HeightRequest="80" />
推荐答案
您将需要为每个平台创建一个自定义渲染器,以使占位符像这样:
You will need to create a custom renderer for each platform to aling the placeholder something like this:
public class PlaceholderEditor : Editor
{
public static readonly BindableProperty PlaceholderProperty =
BindableProperty.Create<PlaceholderEditor, string>(view => view.Placeholder, String.Empty);
public PlaceholderEditor()
{
}
public string Placeholder
{
get
{
return (string)GetValue(PlaceholderProperty);
}
set
{
SetValue(PlaceholderProperty, value);
}
}
}
public class PlaceholderEditorRenderer : EditorRenderer
{
public PlaceholderEditorRenderer()
{
}
protected override void OnElementChanged(
ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var element = e.NewElement as PlaceholderEditor;
this.Control.Hint = element.Placeholder;
}
}
protected override void OnElementPropertyChanged(
object sender,
PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == PlaceholderEditor.PlaceholderProperty.PropertyName)
{
var element = this.Element as PlaceholderEditor;
this.Control.Hint = element.Placeholder;
}
}
}
这篇关于Xamarin表单中的占位符文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文