emoji.wpf
emoji.wpf copied to clipboard
emoji:TextBox.TextChanged Not working as expected
emoji:TextBox.TextChanged And emoji:RichTextBox.TextChanged I want to get the input characters in the TextChanged event, but they are always lagging. Unlike the vanilla TextBox which can get it immediately.
Can you be more specific about what you mean by lagging? Is there a delay before the event is triggered, or are the characters wrong?
This is how I would do it with RichTextBox:
EmojiRichTextBox.TextChanged += (o, e) =>
{
System.Diagnostics.Debug.WriteLine($"TextChanged fired! ({e.Changes.Count} changes)");
var doc = (e.Source as Emoji.Wpf.RichTextBox).Document;
foreach (var c in e.Changes)
{
var range = new System.Windows.Documents.TextRange(
doc.ContentStart.GetPositionAtOffset(c.Offset),
doc.ContentStart.GetPositionAtOffset(c.Offset + c.AddedLength));
var text = range.Text;
System.Diagnostics.Debug.WriteLine($" [{c.Offset}] +{c.AddedLength} -{c.RemovedLength} -> '{text}'");
}
};
And typing in the RichTextBox gives:
TextChanged fired! (1 changes)
[2] +1 -0 -> 'H'
TextChanged fired! (1 changes)
[3] +1 -0 -> 'i'
TextChanged fired! (1 changes)
[4] +1 -0 -> '♥'