HandyOrg / HandyOrg/HandyControl

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

Open
#1,148 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
7.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the problem with a WPF hc:TextBox using ShowClearButton="True" and a non-nullable int binding, then inspect the clear-button and binding conversion path. The fix is done when clearing the control assigns the binding type's default value, such as 0 for int, without leaving the TextBox in an error state.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.