I have already seen that the TextBlock
property does not have an event when the text changes. Is there any way to do an event when the text changes?
* Remembering that it is for WPF and not Windows Forms. This question is only for WPF.
I have already seen that the TextBlock
property does not have an event when the text changes. Is there any way to do an event when the text changes?
* Remembering that it is for WPF and not Windows Forms. This question is only for WPF.
Use a binding for the Text
property and set it to DataContext
of the screen. From here you can use NotifyOnTargetUpdated
and TargetUpdated
, like this:
<TextBlock Name="textBlock1" Text="{Binding MeuTexto, NotifyOnTargetUpdated=True}"
TargetUpdated="textBlock1_TextChanged"/>
There in the class use the new textBlock1_TextChanged
method to handle.
In the constructor of your class or in the Loaded
event, add this. Font
DependencyPropertyDescriptor dp = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));
dp.AddValueChanged(textblock_principal, (object a, EventArgs b) =>
{
// texto alterado!
});