By default, a WPF TextBox
binding sets a string property to an empty string if you first enter some text and then clear it again. I understand the logic for this choice but this means that the database can contain both NULL
and empty string values for these fields.
It would be good practice to always check for NULL
and empty string when retrieving and using these values, but I want to tackle the problem at the core.
There are several solutions: WPF Converters
, convert empty strings to NULL
in the business layer or using TargetNullValue
:
<TextBox Text="{Binding Value, TargetNullValue=''}"/>
Unfortunately, these solutions need to be implemented for individual properties and TextBoxes
.
Is there a way to make all TextBoxes
convert empty strings to NULL
values?