It looks like the problem is that you're creating new members that conflict with those on the base TextBox
. You should consider using the TextChanged
event that already exists on TextBox
, or if you do need your own, name it something different. Here so far you aren't doing anything that the base properties don't do for you already.
The main issue with your specific question though appears to be with the new TextProperty
that you created. You shouldn't hide a dependency property on a base class, primarily because you can't control which one will be used in every situation, but also because there are mechanisms built in to make it unnecessary. In your case you've aggravated the problem by not fully implementing the boilerplate code for a DP. Because you have no wrapper property, your setting of the Text property from code is setting TextBox.Text
, which internally is calling SetValue
with TextBox.TextProperty
, hence skipping your code entirely.
Instead of declaring your own TextProperty
you can just tack on your metadata to the existing one. To add a change handler to the existing property add this call into a static constructor:
TextProperty.OverrideMetadata(GetType(MyCustomTextBlock),
New FrameworkPropertyMetadata(String.Empty,
New PropertyChangedCallback(AddressOf TextPropertyChanged)))