Copy label text for copy/padte issue for only a specific label

Haviv Elbsz 2,071 Reputation points
2022-12-15T11:46:38.347+00:00

Hi all

l have a window of a label text.

i want the user to be allowed to copy
this label text.

currently any label in my app allowed
to copy text and that is bad user experience.

please help

Thank you very much

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,340 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,804 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 73,846 Reputation points Microsoft Vendor
    2022-12-16T02:51:50.303+00:00

    Hello,

    and now I want it only for one label for a specific label.

    You can create a custom label that extend the Label.

       public class MyLabel : Label  
       {  
         
         
       }  
    

    Then use this MyLabel in your xaml layout. and you need local namespace like following code.

       <ContentPage   
         
         
       x:Class="MauiFullScreenDemo.MainPage"    
         
       //you need add the local name space                   
       xmlns:local="clr-namespace:MauiFullScreenDemo" >  
         
         
       <local:MyLabel Text="this is a text"></local:MyLabel>  
    

    In the end, you can set the handler when the label is MyLabel.

       Microsoft.Maui.Handlers.LabelHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>  
               {  
                   if (view is MyLabel)  
                   {  
         
       #if ANDROID  
                  handler.PlatformView.SetTextIsSelectable(true);  
         
       #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.


0 additional answers

Sort by: Most helpful

Your answer

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