开发者

IValueConverter - Get source object at Convert method

开发者 https://www.devze.com 2023-01-29 22:44 出处:网络
Is there a way to get the source object in the Conv开发者_开发问答ert method of a Converter class. I know how to get the converted property but is it possible to get the object that the property belon

Is there a way to get the source object in the Conv开发者_开发问答ert 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?


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消