UI, Xamarin

Copying text from our applications in Xamarin Forms

It’s important that the users can copy relevant texts from their applications. That’s why I explain you a simpler way to do it. Let’s see!

We will follow these steps:

  • Adding the Xamarin.Plugins.Clipboard
  • Supported platforms
  • Adding Copy/Paste actions in our applications
  • Creating an example

First of all.. What do I need?

✔ Add from NuGet Package the plugin: Xamarin.Plugins.Clipboard:

Supports following platforms:

Xamarin.Android  – Xamarin.iOS – Xamarin.Mac – Windows 10 UWP – Gtk# 2.12


Let’s start!

How to add copy and paste action in our application?

To use it, we have to activate properties that allow us to copy and gets the selected text. Now, I´m going to explain you each of them:

  • ✏ SetText: This property sets the text that you want to copy from your application. Accepts a string value.

  • ? GetTextAsync: Gets the text copied. this property is a Task-based API and that’s the reason why we need to  use  the await, like I show you in the example. Returns a Task<string> value.


Creating an example

XAML:

C# code:


Good luck with your implementation! ?

Spanish post:

https://medium.com/@reyes.leomaris/copiando-texto-de-nuestras-aplicaciones-en-xamarin-forms-4ca0c6bf484d

References:

https://github.com/stavroskasidis/XamarinClipboardPlugin

Tagged , ,

Leave a Reply

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