我不知道如何在輸入框中放置佔位符文本。 我有一個非常大的輸入框,並希望將佔位符文本放在頂部。Xamarin表單中的佔位符文本對齊方式
<Entry Placeholder="Enter notes about the item"
Keyboard="Text" VerticalOptions="Start" HeightRequest="80" />
我不知道如何在輸入框中放置佔位符文本。 我有一個非常大的輸入框,並希望將佔位符文本放在頂部。Xamarin表單中的佔位符文本對齊方式
<Entry Placeholder="Enter notes about the item"
Keyboard="Text" VerticalOptions="Start" HeightRequest="80" />
您需要爲每個平臺創建一個自定義渲染到阿玲佔位符是這樣的:
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;
}
}
}
它在android渲染器中工作正常。但是,這個.Control.Hint在iOS裏沒有找到! –
要執行iOS渲染器,代碼將有所不同,請參閱此頁:https://github.com/jimbobbennett/JimLib.Xamarin/blob/master/JimLib.Xamarin.ios/Controls/ExtendedEntryRenderer.cs –
請添加一些代碼/佈局(你試了一下到現在爲止),並描述正是你想。否則幾乎不可能幫助 – Joehl
到目前爲止您嘗試了什麼? –