Wpf – How to detect a change in the Text property of a TextBlock

textblockwpf

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)

Best Solution

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");
});
Related Question