开发者

Bind a Converter defined in the code behind

开发者 https://www.devze.com 2023-03-28 02:08 出处:网络
As part of the solution refactoring I had to move the Converter in to a Dependency Injected UI service. Now my ValueConverter is present inside an Instance. Earlier I had defined a local resource and

As part of the solution refactoring I had to move the Converter in to a Dependency Injected UI service. Now my ValueConverter is present inside an Instance. Earlier I had defined a local resource and mentioned it for the Converter which worked like a charm. After refactoring as mentioned, I tried my luck in Binding to Converter and it just said Binding cannot be done to Converter. Reading this http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d6a95f05-4338-44a4-a834-bbfe71e893ac/ found its by design.

Can you please tell me how to specify my Converte开发者_如何转开发r in xaml which is present inside an instance in the code behind (say UIHelperService.FormatConverter in the Views code behind).


If the converter can be shared between instances, make it a static member somewhere and then....

{Binding Whatever Converter={x:Static src:MyClass.MyConverter}}

If it's an instance member, you may need to manually set up the binding in code-behind... but converters should almost never be instance-specific. Instead, you can use ConverterParameters to achieve this behavior if you need it.

0

精彩评论

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