As far as I know, you have to write your own implementation for this. Here's what I use:
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolValue = (bool)value;
boolValue = (parameter != null) ? !boolValue : boolValue;
return boolValue ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
And I generally set ConverterParameter='negate'
so it's clear in code what the parameter is doing. Not specifying a ConverterParameter makes the converter behave like the built-in BooleanToVisibilityConverter. If you want your usage to work, you can, of course, parse the ConverterParameter using bool.TryParse()
and react to it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…