Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wpf

textblock

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)


1 Answers

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");
});
like image 78
Tono Nam Avatar answered Sep 04 '25 23:09

Tono Nam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!