Skip to content

Instantly share code, notes, and snippets.

@TinkerWorX
Created January 31, 2018 09:19
Show Gist options
  • Save TinkerWorX/6b0e049146eda5a74233bdc79ab57fd5 to your computer and use it in GitHub Desktop.
Save TinkerWorX/6b0e049146eda5a74233bdc79ab57fd5 to your computer and use it in GitHub Desktop.
public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter
{
public Visibility WhenTrue { get; set; }
public Visibility WhenFalse { get; set; }
public Visibility WhenNull { get; set; }
public override object ProvideValue(IServiceProvider serviceProvider) => this;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var boolean = value as bool?;
if (boolean == null)
return this.WhenNull;
return boolean.Value ? this.WhenTrue : this.WhenFalse;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException($"{nameof(NullableBoolConverter)} only supports one way bindings.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment