Share via

Selection and copy is working in editor(in read-only state) in .net maui

Vijayadharshini M 20 Reputation points
2023-10-30T11:46:45.0566667+00:00

I am using editor of .net Maui. Even when I set IsReadOnly true I am able to select text and copy the text. How to disable selection in windows?

Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-10-31T05:55:03.8766667+00:00

    Hello,

    How to disable selection in windows?

    You can do this by Handler. You can get Microsoft.UI.Xaml.Controls.TextBox control

    Attach to the SelectionChanging event and the SelectionLength = 0; and that will stop the selection from occurring.

    
      Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
                {
    #if WINDOWS
                  
                  if (view.IsReadOnly)
                   {
         
                       Microsoft.UI.Xaml.Controls.TextBox res = handler.PlatformView;
                       res.SelectionChanging += (o, e) =>
                       {
                          res.SelectionStart = 0;
    
    
                   };
                 }
    #endif
                });
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jonas Miguel 0 Reputation points
    2026-02-08T03:22:30.28+00:00

    bom de maiss

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.