Wpf 可为Null的数据库属性,但删除内容时texbox仍显示红色边框

Wpf 可为Null的数据库属性,但删除内容时texbox仍显示红色边框,wpf,validation,entity-framework-4,binding,Wpf,Validation,Entity Framework 4,Binding,您好,我正在将WPF文本框绑定到实体框架属性,如下所示: <TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" /> <EdmScalarPropertyAttribute(EntityKeyProperty:=false, IsNullable:=true)> <DataMem

您好,我正在将WPF文本框绑定到实体框架属性,如下所示:

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" />
<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)

它与属性绑定良好,当我更改它时,它会按预期保存到DB。但是如果我删除文本框的内容,我会在它周围看到红色的错误边框。我没有任何验证器,所以我猜texbox正在抱怨该值不可为空。但事实上,DB中的这个属性是可以为null的,所以我无法理解为什么它会出错

系统生成的EF特性定义如下:

<TextBox Grid.Column="1" Grid.Row="0" Margin="5,2" 
         Text="{Binding Path=MyEntityObject.SizeLower, Mode=TwoWay}" />
<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)

公共属性SizeLower()可为null(全局.System.Int64的)
得到
返回_SizeLower
结束
设置
OnSizeLowerChanged(值)
报表属性更改(“SizeLower”)
_SizeLower=StructuralObject.SetValidValue(值)
ReportPropertyChanged(“SizeLower”)
OnSizeLowerChanged()
端集
端属性
Private _SizeLower可为空(对于Global.System.Int64)
我有什么遗漏吗?我认为绑定系统能够确定属性是否可以为null,如果可以,是否允许为null

我怎样才能知道错误是什么?悬停似乎不起作用

谢谢你的建议

=================================== 附加信息

如果我选择全部并删除,然后更改焦点,则会出现验证框。这里有一个前后截图。此外,我已经确认,我可以在数据库中手动为绑定属性设置null,因此这不是问题所在

否认。试图把图片放在这里,但我没有10分。。。!
这里是一个场外链接:

您应该将
TargetNullValue
属性添加到绑定中:

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


这告诉绑定将MyEntityObject.SizeLower中的null值视为string.empty以显示,将string.empty设置为null。

TripleAndGen。。当删除文本时显示红色边框时,你能上传截图吗?我想亲自看看这个。。因为它看起来很奇怪:|。。。也许截图可以帮助我们回答您的问题。:-)谢谢Nawaz,请看修改后的问题。图片是在一个非现场链接,因为它不会接受一个图片,直到我有10分。啊,你是一个传奇菲利普·里克,这就成功了!!非常感谢。同样,谢谢菲利普的回答!工作得很有魅力!