Created
January 31, 2018 09:19
-
-
Save TinkerWorX/6b0e049146eda5a74233bdc79ab57fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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