views:

30

answers:

2

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.

A: 

So let me get this straight... you want the text to be bound to null instead of string.empty?

If this is the case, instead of binding via the converter, you COULD bind to a property in a view model (if you dont have a viewmodel, you can create it and bind your xaml to it).

That property in question could then return (in the getter section of the property) a null value rather than a string.empty.

If this doesn't solve your problem please describe in more detail and why you want to bind to a null instead of a string.empty.

AlvinfromDiaspar
+2  A: 

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=''}" />
Quartermeister