WPF文本框接受INT但不是NULLABLE INT?

Sui*_*eep 11 c# wpf int nullable

模型

public int? SizeLength { get; set; }
Run Code Online (Sandbox Code Playgroud)

XAML

<TextBox Text="{Binding [someViewModel].SizeLength, Mode=TwoWay}"></TextBox>
Run Code Online (Sandbox Code Playgroud)

一旦用户尝试backspacedelete其中的值textbox,一条消息Value '' cannot be converted.

我可以知道它有什么问题吗?

小智 26

使用:

{Binding TargetNullValue=''}
Run Code Online (Sandbox Code Playgroud)

  • @ Mr.SuicideSheep - 您需要将其设置为空字符串,如答案中所述,而不是0. (3认同)