Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Is there a way to bind to a Nullable<Int32> property without using a value converter?

Tags:

binding

wpf

Is there a way to bind to a Nullable property without using a value converter?

Currently I have this...

<DataGridTextColumn Header="ApplicationKey" Binding="{Binding ApplicationKey, ValidatesOnDataErrors=True, Converter={StaticResource ResourceKey=TestConverter}}" />

Without the converter it thinks of an empty textbox as a String.Empty instead of a Null.

I'm hoping there is some sort of magic property like TargetNullValue.

like image 775
Jonathan Allen Avatar asked Jul 19 '10 23:07

Jonathan Allen


1 Answers

Yes, the TargetNullValue property on Binding should do exactly what you want. If you set TargetNullValue to the empty string, then the binding will convert the empty string to null and back:

<DataGridTextColumn Header="ApplicationKey" Binding=
    "{Binding ApplicationKey, ValidatesOnDataErrors=True, TargetNullValue=''}" />
like image 73
Quartermeister Avatar answered Sep 26 '22 08:09

Quartermeister