Texblock - Make a text change event

Asked

Viewed 39 times

2

I’ve seen the property of TextBlock does not have an event when changing text. Is there any way to do an event when the text is changed?

* Remembering that it is for WPF and not Windows Forms. This question is only for WPF.

  • And if you used a Textbox taking out the styles, leaving it identical to Textblock?

  • I use TexBlock because of this property: TextTrimming="CharacterEllipsis", it seems that the TextBox does not own this property.

1 answer

2


Code-Behind Binding

Use a Binding for the property Text and seven in the DataContext of the screen. From there you can use the NotifyOnTargetUpdated and the TargetUpdated, thus:

<TextBlock Name="textBlock1" Text="{Binding MeuTexto, NotifyOnTargetUpdated=True}" 
           TargetUpdated="textBlock1_TextChanged"/>

In the class use the new method textBlock1_TextChanged to treat.

Dependency Property

In your class builder or event Loaded, add that. Source

DependencyPropertyDescriptor dp = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));

dp.AddValueChanged(textblock_principal, (object a, EventArgs b) =>
{
      // texto alterado!
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.