I have a control that I want to show/hide, depending on the value of a boolean.
I have a NegatedBooleanConverter (switches true to false and vice versa) and I need to run this converter first. I have a BooleanToVisibilityConverter and I need to run this converter after the NegatedBoolConverter.
How can I fix this problem? I want to do this in XAML.
edit: this is a possible solution.
That doesn't seem to work. It first converts the value with the seperate converters and then does something with the converted values.
What I need is:
- Convert the value with the first converter (this gives convertedValue).
- Convert convertedValue with the second converter and it's this result that I need.
What we do in our project is make a regular BooleanToVisibilityConverter, said converter takes one parameter (anything at all, a string, an int, bool, whatever). If the parameter is set it inverts the result, if not, it spits out the regular result.
To address this specific problem, instead of using two converters your could write your own BoolToVisibilityConverter that uses the ConverterParameter (as a bool) to determine whether or not to negate the original Boolean.
To answer my own question again: I have been using this solution for years now: http://www.codeproject.com/Articles/15061/Piping-Value-Converters-in-WPF
It makes a new converter of 2 existing converters, calling the first one first, and then the second one etc etc.
I'm pretty pleased with this solution.
Expanding on Natrium's great answer...
XAML
Class
This is what I did:
and I call it like this:
A MultiValueConverter might also be possible I think. Maybe I'll try that later.
I think you may want to use a Multiconverter here instead of two separate converters. You should be able to reuse the logic from your existing converters. Check out this discussion for a start.