how to multiple times convert value in WPF
I have a 2 converter.
- Boolean to Visibility(Bool2Visible) - This converter convert Boolean value to Visibility enum
- Invert Boolean(InvertBool) - this converter invert Boolean value
My xaml is here
<stackpanel Name="A"
visibility="{Binding isTrue,Converter={StaticResource Bool2Visible}}"/>
<stackpanel Name="B"
visibility="{Binding isTrue,Converter={StaticResource Bool2Visible}}"/>
My goal is If isTrue=true, Stackpanel B will hidden. I need to use InsertBool and use Bool2Visible in Stackpanel B binding.
How to use 2 converter in one time.
Otherwise. newvalue=Bool2Visible(InsertBool(开发者_如何学JAVAvalue))
If it is impossible, I can to create InvertAndConvertToVisibility
converter.
If it is impossible, i can to create InvertAndConvertToVisibility converter.
Personally i would just say to take this option, it is less than 5 minutes worth of work, and if you use a separate converter and name it appropriately it is obvious what you intend to happen.
An alternative is to modify your Bool2Visible
converter use the parameter
parameter to pass a flag which indicates that the operation should be negated.
I would rather use a special MultiValueConverter if you need to have a value determined from two seperate inputs!
You can expand Bool2Visible converter with some logic that checks ConverterParameter. In the binding in 2nd StackPanel add ConverterParameter="invertValue" and inside converter class check the value of the parameter(ConverterParameter is automatically passed).
In that way you can handle your problem.
精彩评论