Search code examples
c#wpfclipboardemoji

System.Windows.Copy() does not work with Emojis


I've been trying to get copying emojis to clipboard to work in various ways, but nothing works. Emojies simply get substituted for spaces.

Clipboard.SetText(message, TextDataFormat.UnicodeText);

I've tried doing various conversions, but they do not give any results either.

Although, if I paste the same emoji to a TextBox and then try to copy it back - it works. I even tried creating a TextBox from code-behind, fill it with my message and copy it again - doesn't work.


Solution

  • I used the following example and it worked for me:

        public MainWindow()
        {
            InitializeComponent();
    
            TextBlock tb = new TextBlock();
            var ch = char.ConvertFromUtf32(128076);
            tb.Text = ch.ToString();
            Clipboard.SetText(ch.ToString(), TextDataFormat.UnicodeText);
            tb.Text += Clipboard.GetText(TextDataFormat.UnicodeText);
            this.Content = tb;
        } 
    

    The TextBlock.Text is 👌👌. Maybe the question is about how you manage getting the Text back!