为什么我们需要在IValue Converter中使用ConvertBack
我不确定为什么我们需要在 IValueConverter
中使用 I ConvertBack
方法。
在 Convert
方法本身中,我们进行转换并返回要绑定在控件中的更新值。
那么什么场景下我们应该使用Convertback。我知道这个问题非常基本,但只是想弄清楚基本原理。
非常感谢您的帮助和建议。
谢谢, 苏本
I am not sure Why we need to use I ConvertBack
method in IValueConverter
.
In the Convert
method itself we do the conversion and return the updated value to be bound in our control.
So in which Scenario we should use Convertback. I know this question is very basic but just wanted to make the fundamentals clear.
Thanks a lot for your help and suggestions.
Thanks,
Subhen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不经常使用它,但据我了解,它是在绑定更新源值时使用的。无论您的绑定在何处更新源(通常在视图模型上)并指定转换器,它将使用 ConvertBack。
所以举一个捏造的例子;如果您的转换器在双精度值的开头添加了货币符号,则当用户更改该值时,您的转换器会希望在尝试在虚拟机上设置双精度值之前再次删除该符号。
I don't use it often, but it's my understanding it's for when a binding updates the source value. Wherever your binding updates the source (on the view model usually), and specifies a converter, it will use ConvertBack.
So to give a fabricated example; if your converter added a currency symbol to the start of a double, when a user changed that value your converter would want to remove the symbol again before trying to set the double value on your VM.