Nullable database property but texbox still shows red border when content deleted

Hi I am binding a WPF textbox to an Entity Framework property as follows:

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" />

It binds fine to the property and when I change it, it saves to the DB as expected. But if I delete the content of the Textbox I get the red error border around it. I dont have any validator in place so I am guessing the texbox is complaining about the value not being nullable. But in fact this property in the DB is nullable, so I cannot understand why it would error.

The system generated EF property definition is as follows:

<EdmScalarPropertyAttribute(EntityKeyProperty:=false, IsNullable:=true)>
<DataMemberAttribute()>
Public Property SizeLower() As Nullable(Of Global.System.Int64)
    Get
        Return _SizeLower
    End Get
    Set
        OnSizeLowerChanging(value)
        ReportPropertyChanging("SizeLower")
        _SizeLower = StructuralObject.SetValidValue(value)
        ReportPropertyChanged("SizeLower")
        OnSizeLowerChanged()
    End Set
End Property

Private _SizeLower As Nullable(Of Global.System.Int64)

Is there something I am missing? I thought the binding system was able to determine if a property was nullable and allow nulls if so?

How can I see what the error is? Hovering doesnt seem to do the trick.

Thanks for any advice.

=================================== ADDITIONAL INFO

If I select all and delete, then change focus, the validation box appears. Here's a screencapture before and after. Also I have confirmed that I can manually put NULLs in the database for the bound properties so thats not the problem.

DENIED. Tried to put picture here but I dont have 10 points...! Here is an offsite link instead: CLICK HERE

Answers


You should add the TargetNullValue property to your binding:

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, 
         Mode=TwoWay, 
         TargetNullValue=''}" />

This tells the binding to treat null values in MyEntityObject.SizeLower as string.empty for display, and string.empty as null when setting.


Need Your Help

JSTL: iterate list but treat first element differently

java jstl jsp-tags

I'm trying to process a list using jstl. I want to treat the first element of the list differently than the rest. Namely, I want only the first element to have display set to block, the rest shoul...

how to best approach to use spring batch annotation or xml files ?

spring spring-batch

firstly, thanks for attention,in my spring batch project defined many jobs , for example:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.