Align bookmark text in Xamarin forms

I do not know how to transfer the placeholder text to the input field. I have an input field that is very large and wants to put the placeholder text at the beginning.

<Entry Placeholder="Enter notes about the item" 
       Keyboard="Text" VerticalOptions="Start" HeightRequest="80" />
+4
source share
2 answers

You will need to create your own renderer for each platform to smooth 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;
        }
    }
}
+3
source

You no longer need to configure, you only need to use it in XAML: HorizontalTextAlignment="Center"

0
source

Source: https://habr.com/ru/post/1608959/


All Articles