IValueConverter - 在 Convert 方法中获取源对象

发布于 2024-10-07 15:50:24 字数 75 浏览 9 评论 0原文

有没有办法在 Converter 类的 Convert 方法中获取源对象。我知道如何获取转换后的属性,但是是否可以获取该属性所属的对象?

Is there a way to get the source object in the Convert method of a Converter class. I know how to get the converted property but is it possible to get the object that the property belongs to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

你是暖光i 2024-10-14 15:50:24

正如 Darin 所说,这对于 IValueConverter 来说是不可能的。您也不能将其分配给 ConverterParameter,因为它不是依赖项属性。但是,如果您采用 MultiBinding 的方式,这是可能的。这样,您实际上可以绑定到调用对象,并且 IMultiValueConverter 将接收绑定值数组中的对象。这个MSDN线程有一个简单的例子...

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9f3e4f6d-20d2-4c13-90a2-7c157ed4f8c3/

As Darin says, this isn't possible with an IValueConverter. You can't assign it to ConverterParameter either because it's not a dependency property. However it is possible if you go down the route of MultiBinding. That way, you can actually bind to your calling object, and the IMultiValueConverter will receive the object in the binding value array. This MSDN thread has a quick example...

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9f3e4f6d-20d2-4c13-90a2-7c157ed4f8c3/

樱桃奶球 2024-10-14 15:50:24

不,这是不可能的。此信息永远不会传递到转换 方法。值转换器还通过指定源类型和目标类型来工作。如果需要访问父对象,请在对象层次结构中定义更高一级的源类型。

No, it is not possible. This information is never passed to the Convert method. Also a value converter works by specifying a source and destination type. If you need to access the parent object define the source type one level higher in the object hierarchy.

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