将值设置为空值在WPF结合 [英] Set value to null in WPF binding

查看:113
本文介绍了将值设置为空值在WPF结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看看下面的行

<TextBox Text="{Binding Price}"/>

从上面这个价格属性是十进制?(可空十进制)。

我想,如果用户删除文本框的内容(即进入空字符串,它应该automatcally更新源空(在VB中为Nothing)。

I want that if user deletes the content of the textbox (i.e. enters empty string, it should automatcally update source with null (Nothing in VB).

我如何能做到这一点Xamly任何想法?

Any ideas on how I can do it 'Xamly'?

推荐答案

我使用.NET 3.5 SP1所以这是非常简单的:

I am using .NET 3.5 SP1 so it's very simple:

<TextBox Text="{Binding Price, TargetNullValue=''}"/>

它代表(感谢格雷戈尔的评论):

Which stands for (thanks Gregor for your comment):

<TextBox Text="{Binding Price, TargetNullValue={x:Static sys:String.Empty}}"/>

SYS 的mscorlib 系统 C>:

sys is the imported xml namespace for System in mscorlib:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

希望有所帮助。

Hope that helped.

这篇关于将值设置为空值在WPF结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆