How to detect a change in the Text property of a TextBlock?

John Parker picture John Parker · Mar 31, 2009 · Viewed 32.2k times · Source

Is there any way to detect a change in the Text property of a TextBlock element using events?

(I'm trying to provide an animation for highlighting the TextBlocks whose Text property change within a DataGrid)

Answer

Tono Nam picture Tono Nam · Aug 26, 2015

It's easier than that! Late answer, but much simpler.

// assume textBlock is your TextBlock
var dp = DependencyPropertyDescriptor.FromProperty(
             TextBlock.TextProperty,
             typeof(TextBlock));
dp.AddValueChanged(textBlock, (sender, args) =>
{
    MessageBox.Show("text changed");
});