1

I've implemented a BorderlessEditor in my Xamarin.Forms application using a custom EditorRenderer, but I'm facing the issue that the editor text is not selectable at all in both cases, neither in Forms editor control nor in Rendered native editor control. My app has the functionality to let user copy paste the text in the editor while typing, like in any other text editing app. This is a basic feature in most of the apps and is by default there. But it's not working in my app. I've tried enabling it through

Control.SetTextIsSelectable(true);

but still it's not working. I've tried other things too, like:

Control.CustomSelectionActionModeCallback = new 
CustomSelectionActionModeCallback();
Control.CustomInsertionActionModeCallback = new CustomInsertionActionModeCallback();

But nothing is working at all and text is not getting selected, not even a single word. Does anyone have any idea about this issue? How can I make the text selectable and allow default copy paste feature in custom editor?

Here's my code in XAML:

<renderer:BorderlessEditor
    Grid.Row="1"
    x:Name="UserTextEditorAndroid"
    BackgroundColor="{StaticResource WhiteColor}"
    HeightRequest="350"
    Margin="20,2"
    MaxLength="1024"
    IsReadOnly="{Binding Source={x:Reference LongTextTemplate}, Path=Editable, Converter={StaticResource InverseBool}}" />

And the custom render code is:

public class BorderlessEditorRenderer : EditorRenderer
{
    public BorderlessEditorRenderer()
    {
    }

    public static void Init() { }
    protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
    {
        base.OnElementChanged(e);
        if (e.OldElement == null)
        {
            Control.Background = null;

            var layoutParams = new MarginLayoutParams(Control.LayoutParameters);
            layoutParams.SetMargins(0, 0, 0, 0);
            LayoutParameters = layoutParams;
            Control.LayoutParameters = layoutParams;
            Control.SetPadding(0, 0, 0, 0);
            SetPadding(0, 0, 0, 0);
            Control.SetTextIsSelectable(true);
            Control.VerticalScrollBarEnabled = false;
        }
    }
}

Even if I use Xamarin.Forms' own editor in XAML instead of a custom renderer it doesn't work. The text is still not selectable.

Julian
  • 5,290
  • 1
  • 17
  • 40
Nidhi Sood
  • 125
  • 1
  • 1
  • 7

0 Answers0