Last active
March 15, 2016 14:40
-
-
Save JohanLarsson/c165925b768bc6ec8c0d to your computer and use it in GitHub Desktop.
This file contains 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
[MarkupExtensionReturnType(typeof(IValueConverter))] | |
public class BooleanToVisibilityConverter : MarkupExtension, IValueConverter | |
{ | |
public Visibility WhenTrue { get; set; } = Visibility.Visible; | |
public Visibility WhenFalse { get; set; } = Visibility.Collapsed; | |
public Visibility WhenNull { get; set; } = Visibility.Collapsed; | |
public override object ProvideValue(IServiceProvider serviceProvider) | |
{ | |
return this; | |
} | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
if (value is bool) | |
{ | |
return Equals(value, true) ? WhenTrue : WhenFalse; | |
} | |
return WhenNull; | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotSupportedException("Only supports one way bindings"); | |
} | |
} |
This file contains 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
<DataGrid Visibility="{Binding HasItems, | |
RelativeSource={RelativeSource Self}, | |
Converter={local:BooleanToVisibilityConverter WhenTrue=Collapsed, WhenFalse=Visible}}" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment