在我的数据库选项卡中,我有一列可以包含 Guid,也可以是 NULL。在我的视图模型中,此字段配置为 Guid 并绑定到我的DataGrid
。
当我清除DataGrid
中的字段并将值设置为 null 时,我会收到错误"无法识别的 Guid 格式"。 这是正确的,因为 guid 不能为空。但是如何将其显示为 null 或至少将其作为 NULL 传递给数据库?
XAML 绑定:
<DataGridTextColumn Binding="{Binding AttributeTypeValueId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Header="AttributeTypeValueId" />
和我在模型中的属性:
private Guid _attributeTypeValueId;
public Guid AttributeTypeValueId
{
get
{
return _attributeTypeValueId;
}
set
{
if (value != _attributeTypeValueId)
{
_attributeTypeValueId = value;
RaisePropertyChanged("AttributeTypeValueId");
}
}
}
知道我该怎么做吗?
感谢!
您可以使用可为空的:
private Guid? _attributeTypeValueId;
将字段和属性的类型更改为 Guid? 应该没问题。我刚刚测试了它。