HandyControl icon indicating copy to clipboard operation
HandyControl copied to clipboard

当设置hc:TextBox的属性ShowClearButton=true时,某些情况下点击清除按钮,会引起无法消除的错误异常.

Open steveyan00 opened this issue 2 years ago • 0 comments

Describe the bug

当设置hc:TextBox的属性ShowClearButton=true,Text Binding变量类型为int等不可为null的类型的情况时,点击清除按钮会引起无法消除的错误异常.

Steps to reproduce the bug

  1. MainViewModel中public int IntVar;
  2. <hc:TextBox ShowClearButton="True" Text={Binding Variable} />
  3. 点击Clear按钮.
  4. 文本框变红,且不可消除. 错误信息:ConvertBack cannot convert value '' (type 'String'). BindingExpression:Path=IntVar; DataItem='MainViewModel' (HashCode=xxxxxxxx); target element is 'TextBox' (Name=''); target property is 'Text' (type 'String') FormatException:'System.FormatException: Input string was not in a correct format. Expected behavior Add a judgment for the empty string. The value can be set to 0 if it is empty.

Expected behavior

点击Clear时,可以变成binding类型的默认值.

Screenshots

image

image

image

image

NuGet package version

HandyControls (Custom version) 3.3.11

IDE

Visual Studio 2022

Framework type

.Net 6.0

Windows version

May 2021 Update (19043)

Additional context

No response

steveyan00 avatar Apr 02 '22 03:04 steveyan00