Tuesday, June 9, 2009

Binding for Converter Parameter

I have come across the situation where I need to do some Binding for ConverterParameter. Something like


I have done lots of research, and I found out that its impossible to do binding for ConverterParameter.
So I came up with the Solution. I created the Converter but inherited from FrameworkElement

public class ShowDeleteServiceConverter : FrameworkElement, IValueConverter

In the converter class, I created a dependency property



Now, I can do the Binding as usual

And



It might not be the best solution, but it works for me so far. If you have any idea, feel free to drop me comments.

Cheers,

10 comments:

Unknown said...

You're a star. I been struggling with this for half a day now. Finally an example that could be applied to a real life scenario.

mark_southaustin said...

Nice, you successfully moved the meatball!

Xavier Poinas said...

This is awesome. Note that you can also use DependencyObject as a base class, which is a lower lever class than FrameworkElement.

Todor Todorov said...

How did you make it work ? On my tests the Convert method is being called first, before the binding to the property has passed. This way the property I try to use inside the Convert method is always NULL.

Sue Maurizio said...

I don't know if it's elegant, but it's pretty smart

Bruno Beraldo said...

Brilliant!!

It's fitted like a glove!

Thank you very much!!!

Unknown said...

You're welcome. Glad you liked it

Mikel said...

Great idea - just doesn't work for dynamically changed objects. But still worth to use when someone needs it.

Nidhi said...

Brilliant!!!
I would say a very clean approach.

Dušan Knežević said...

thanks Brandon, it's a nice idea. It's been very useful too!