locked
Unable to select/copy/paste text in Xamarin.Forms Editor or custom Borderless Editor using renderer RRS feed

  • Question

  • User393808 posted

    Hello @JamesMontemagno ,

    I've implemented Borderless Editor in my Xamarin.Forms application using Custom EditorRenderer. But I'm facing an 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 even a single word. Does anyone has any idea about this issue? How can I make the text selectable and allow default copy paste feature in custom editor?

    Thanks in advance !

    Wednesday, April 8, 2020 7:40 AM

All replies

  • User369978 posted

    I've implemented Borderless Editor in my Xamarin.Forms application using Custom EditorRenderer.

    Could you post the code ?

    I test on normal Editor , it works fine .

    Wednesday, April 8, 2020 10:41 AM
  • User393808 posted

    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:

    `protected override void OnElementChanged(ElementChangedEventArgs 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.VerticalScrollBarEnabled = false;
            }
        }`
    
    Wednesday, April 8, 2020 11:40 AM
  • User369978 posted

    The issue is caused by the property IsReadOnly , it indicates whether user should be prevented from modifying(select/copy/paste) the text. Default is false.

    When the value is true , you can't edit the text .

    Friday, April 10, 2020 3:11 PM
  • User89714 posted

    @Nidhi_Sood said: the editor text is not selectable at all in both cases

    The IsReadOnly property results in different behavior of different platforms. On UWP, even with IsReadOnly = true the user can still Select and Copy from the Editor (but not Cut or Paste). However, on Android, is seems that even Select and Copy are inoperable. I haven't done it for Editor, but for Entry ended doing some pretty hacky stuff to get something akin to a readonly Entry that still allowed Select and Copy. I expect the similar hacky stuff would be required for the Editor. TBH, I'm surprised that the Xamarin.Forms Entry and Editor do not do this out-of-the-box.

    cc @ColeX

    Friday, April 10, 2020 5:56 PM
  • User323696 posted

    @JohnHardman I'm often surprised how many things XF doesn't support out of the box, forcing you to go implement custom renderers and hack stuff - even for such basic things like text copy. Here's how you do it in React-Native: <Text selectable={true}>Text that can be selected with native actions on iOS/Android</Text>

    Done. Like...c'mon XF team, seriously... I'm by no way a proponent of RN, in fact I despise it, but geez it makes UI easy.

    Sunday, May 17, 2020 5:37 AM
  • User387208 posted

    Please vote up this enhancement: "Enable selecting and copying text in read only Editor and/or Entry" in Xamarin : https://github.com/xamarin/Xamarin.Forms/issues/14071 and in Maui : https://github.com/dotnet/maui/issues/605

    Saturday, March 27, 2021 11:29 AM
  • User89714 posted

    @elashi said: Please vote up this enhancement: "Enable selecting and copying text in read only Editor and/or Entry" in Xamarin : https://github.com/xamarin/Xamarin.Forms/issues/14071 and in Maui : https://github.com/dotnet/maui/issues/605

    There are at least two open issues already logged that relate to this https://github.com/xamarin/Xamarin.Forms/issues/12930 (which I logged when trying to overcome XF's accessibility limitations highlighted the problem again) and https://github.com/xamarin/Xamarin.Forms/issues/5843

    The latter has been open for nearly two years and still no sign of it being fixed. This really should be done in the XF/MAUI core, but given how long this has been outstanding, I'd suggest working around it in your own code using custom controls/renderers etc (and submitting any solution to Xamarin/Microsoft if appropriate)

    Saturday, March 27, 2021 1:06 PM