Xamarin, Xamarin Essentials

Learning about Clipboard in Xamarin Forms

Howdy! 🙋‍♀️ Happy New Year! 🎄 I hope you had a happy holiday season, in this new year I know you are ready to continue learning! Before we start, I would like to know if you have ever had the need to copy information between applications 🧐. Probably yes! (For example, when you need to copy your bank account number from the App), super useful! And it’s just for this reason that in this article we will be learning a super simple way to do it with Xamarin Essentials.! 💚


Let’s start!

What is Clipboard class?

The Clipboard class allows you to Copy and Paste text to the clipboard so that it can later be shared between applications. This is an API provided by Xamarin Essentials.!


So how can I handle these texts?

We have some very important methods and properties to do it, which I describe step by step below:

🔹 Step 1⃣: Let’s check if the Clipboard has information available

To do it, we have the HasTest property, which is contained in the Clipboard class and returns a Bool value.

🔹Step 2⃣: Setting ClipBoard information

To Set (Copy) the ClipBoard information, we have the SetTextAsync method, which receives a string as a value.

🔹Step 3⃣: Getting ClipBoard information

To Get (Paste) the ClipBoard information, we have the GetTextAsync method, which returns a string as a value.


Finally, we can know when the clipboard content is updated!

We have the ClipboardContentChanged event, which allow us to know each time that the content of the Clipboard has been updated!

⚠ When registering the method, don’t forget to unsubscribe when necessary.


And done! Our ClipBoard is ready for copy and paste text! 😎

Thanks for reading! 💚💕

Spanish post:  https://es.askxammy.com/trabajando-con-el-portapapeles-en-xamarin-forms/

Reference: https://docs.microsoft.com/en-us/xamarin/essentials/clipboard?WT.mc_id=DT-MVP-5003353

Tagged , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *