This is probably a basic question, since I’m new to WPF..
I have a UserControl that contains a TextBox and a Button (code is simplified for this question) :
<UserControl x:Name="this">
<TextBox Text="{Binding ElementName=this, Path=MyProperty.Value}"/>
<Button x:Name="MyButton" Click="Button_Click"/>
</UserControl>
In the code behind I have registered “MyProperty” as DependencyProperty:
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(MyProperty), typeof(MyPropertyNumeric), new UIPropertyMetadata(null));
A “MyProperty” is a class defined by me, that implements INotifyPropertyChanged. “MyProperty.Value” is of type object.
When the button is clicked, I change MyProperty.Value in the code-behind. I want to have the TextBox to automatically show the new value. I would expect that the above would work, since I’ve implemented INotifyPropertyChanged – but it doesn’t.. Anyone knows how to do this?
Are you calling the OnPropertyChanged event with the name of your property when it is updated?
Eg,
It is important to make sure the PropertyChanged event is fired with the name of the property you want to update.