In my WPF application I have a TextBox where the user can enter a percentage (as int, between 1 and 100). The Text property is databound to a property in a ViewModel, where
Try using in xaml Explicit instead of PropertyChanged:
<TextBox Text="{Binding Percentage, Mode=TwoWay, UpdateSourceTrigger=Explicit, TargetNullValue={x:Static System:String.Empty}}"
TextChanged="TextBox_TextChanged" />
and in code behind UpdateSource instead of UpdateTarget
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
// Removed safe casts and null checks
((TextBox)sender).GetBindingExpression(TextBox.TextProperty).UpdateSource();
}
Tested it and it works. Btw this problem will probably be resolved in a later version of .NET.
You can use PropertyChanged. However, try binding to the EditValueProperty dependency instead of the TextProperty dependency (or events). It will work as desired.