All ValueConverter examples I have found used Resources to create ValueConverter instance. But my ValueConverter uses some dependencies which are resolved by IoC framework. So I would like to set Binding Converter property to some property of my ViewModel which is accessible through DataContext. I tried to do it but got an exception telling I can’t bind anything to Converter property of binding.
All ValueConverter examples I have found used Resources to create ValueConverter instance. But my
Share
You cannot bind
Binding.Converteras it is not a dependency property, but you can make the converter inherit fromDependencyObjectand declare dependency properties on that instead, then you can bind those.Note however that you might need to jump some hoops to get what you want as you will not be able to bind to the
DataContext. You probably cannot use ElementName either because the converter will have no name-scope. One common workaround is to target an object with the right DataContext usingBinding.Sourcewithx:Reference. Make sure not to declare to instantiate the converter inside the visual tree of the targeted object orx:Referencewill throw cyclical dependency errors (the targeted object’sResourcesare fine).