Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# WPF display colored emoji instead of black and white

Tags:

c#

wpf

emoji

I'm creating a chat in WPF and I'm trying to make user can send emoji. The user writes a message in a TextBox and he can open menu with emoji and choose some. A probem is that emoji are not colored, but they are black and white.

Not colored :-(

I tried to use emoji.wpf, but it works only in RichTextBox (I need buttons and TextBox too) and the emoji are rendering very slowly. Somewere I read that the only solution is to insert emoji as pictures. Is it true or it exists some better solution? It would be advisable to have emoji as unicode characters, not pictures.

Sorry for my english, I'm from Czech Republic.

like image 273
mozkomor05 Avatar asked Apr 08 '18 18:04

mozkomor05


2 Answers

I wrote Emoji.Wpf; here are a few comments:

  • There is an Image class that can be trivially used in a Button. See for instance the font viewer sample which uses simple XAML like this: <emoji:Image Width="44" Height="44" Text="{Binding UnicodeText}"/>

  • It is quite difficult to subclass TextBox for colour emoji because it only supports a single font and font style; overriding the rendering code seems difficult and I am not skilled enough to do it.

Here is what the font viewer looks like:

Emoji.Wpf font viewer

like image 97
sam hocevar Avatar answered Sep 19 '22 13:09

sam hocevar


I found a very easy and great method!

Just add a Nuget package named "Emoji.Wpf" and use it as below:

<Window ...
        xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
        ...>
    ...
    <emoji:TextBlock FontSize="24" Text="💖😁🐨🐱‍🐉👩🏿‍👩🏻‍👦🏽"/>
    ...
</Window>

enter image description here

And it works well for my WPF app.

More information in it's project site:

https://github.com/samhocevar/emoji.wpf

like image 40
Even Wonder Avatar answered Sep 20 '22 13:09

Even Wonder