Issue
So i am trying to set text of my "Editor" to clipboard. I am reading alot on forums such as xamarin, where people is saying that this is a bug and cannot be done? Is this true?
Because when i am trying to set text to clipboard i get this error "Specified cast is not valid" on the first line.
private void I_Tapping(object sender, MR.Gestures.LongPressEventArgs e)
{
var clipBoard = (ClipboardManager)Context.ClipboardService;
var clip = ClipData.NewPlainText("Link", editorLinkText.Text);
clipBoard.PrimaryClip = clip;
}
I tried to implement this from a xamarin forum site but the "Forms" after (ClipboardManager) is not found for me.
// Get the Clipboard Manager
var clipboardManager = (ClipboardManager)Forms.Context.GetSystemService(Context.ClipboardService);
// Create a new Clip
Android.Content.ClipData clip = Android.Content.ClipData.NewPlainText(title, text);
// Copy the text
clipboardManager.PrimaryClip = clip;
This is a crossplatform project, hens why its not working with clipboardmanager because the .cs file is in the top portion of the project?
I couldn't find the other sites i was looking at but this is one site where they say that this is bugged. But if it isn't, Help me out on this :) https://forums.xamarin.com/discussion/6402/clipboard-copy-paste-problem
King Regards
Solution
I would recommend using this NuGet package: https://www.nuget.org/packages/Xamarin.Plugins.Clipboard/
Really good when dealing with crossplatforming. Download it and use this code and you will be good to go.
using Plugin.Clipboard;
private void I_Tapping(object sender, MR.Gestures.LongPressEventArgs e)
{
CrossClipboard.Current.SetText(editorLinkText.Text);
}
Answered By - Rodnik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.