iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
https://docs.inkore.net/ui-wpf-modern
GNU Lesser General Public License v2.1
326 stars 29 forks source link

TextBox 使用文本框内的清空按钮,不会更新Binding属性 #62

Closed sheng-ri closed 1 week ago

sheng-ri commented 1 month ago

Describe the bug 如题

To Reproduce

  1. 创建一个对象具有一个属性,实现INotifyPropertyChanged
  2. xaml设置Binding,UpdateSourceTrigger=PropertyChanged
  3. 使用按钮清空image

Expected behavior 对应属性会发生变化

Desktop (please complete the following information):

NotYoojun commented 1 month ago

你好,

问题出在 source\iNKORE.UI.WPF.Modern\Controls\Helpers\TextBoxHelper.cs 的第 162 行: image

如果将 SetCurrentValue 改为 SetValue,我猜这会破坏绑定的关系。不知道大家有没有好办法?

sheng-ri commented 1 month ago

咱不是很懂,不过一般来说都是直接设置Text属性吗,为什么需要这样使用

NotYoojun commented 1 month ago

咱不是很懂,不过一般来说都是直接设置Text属性吗,为什么需要这样使用

我记得如果直接设置的话是会破坏掉你原来的 Binding 的。

sheng-ri commented 1 month ago

https://github.com/dotnet/wpf/blob/94d8cc517c1491412018f36069b278c74ebd3bd9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBox.cs#L659 应该不会,设置Text属性,最后会调用set访问器,SetValue(TextProperty, value);会处理binding

NotYoojun commented 1 month ago

那你试试把 SetCurrentValue 改成 SetValue 能不能解决问题?

sheng-ri commented 1 month ago

我个人接触WPF的时间很少,我不确定TextBox.SetValue的实现是如何,我只能确定正常对属性的赋值不会破坏绑定 我也不知道怎么发布nuget包到本地...

NotYoojun commented 3 weeks ago

我也不知道这样子是不是对的。在没有准确答案之前这个修不了。

SlimeNull commented 1 week ago

这个貌似已经修复了? 我 clone 了最新的项目, 并没有发现此问题

NotYoojun commented 1 week ago

我这里啥都没有动。会不会是 @sheng-ri 你绑定的有点问题? 有无时间写一个 example 项目呢?

sheng-ri commented 1 week ago

我这里啥都没有动。会不会是 @sheng-ri 你绑定的有点问题? 有无时间写一个 example 项目呢?

我又试了下,又正常了....看来是我之前绑定有问题,不知道什么时候就改对了