I am Binding a TextBox with a property which is of type float. Everything works fine, I change the value in TextBox and it gets updated in property. The problem occurs when I make the TextBox blank, my property doesn’t get updated, it is still having old value. Now I need to use converter in my binding to update property with default value in case of blank value from TextBox. I want to know Why this behavior? Is there any other solution to this?
Share
Your property is not updating because it’s not possible to convert empty string to float. There are two ways to solve this.
First way is to add a property which type is string, bind the TextBox with it and implement changing of float property. Like this:
Second way is to use a converter:
XAML:
There is an article about converters
I prefer the first way with MVVM pattern.