为什么我们需要在IValue Converter中使用ConvertBack

发布于 2024-09-02 14:14:03 字数 236 浏览 10 评论 0原文

我不确定为什么我们需要在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑疤怪 2024-09-09 14:14:03

我不经常使用它,但据我了解,它是在绑定更新源值时使用的。无论您的绑定在何处更新源(通常在视图模型上)并指定转换器,它将使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文