Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Converts boolean values to arbitrary objects.
- /// </summary>
- /// <example>
- /// Converting view model's boolean property to control visibility:
- /// <Window.Resources>
- /// <infra:BoolConverter x:Key="falseHide" TrueValue="{x:Static sw:Visibility.Visible}" FalseValue="{x:Static sw:Visibility.Hidden}"/>
- /// ...and then...
- /// <SomeControl Visibility="{Binding ViewModelBooleanProperty, Converter={StaticResource falseHide}}">
- /// </example>
- class BoolConverter : IValueConverter
- {
- public object TrueValue { get; set; }
- public object FalseValue { get; set; }
- public object NullValue { get; set; }
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- if (!(value is bool))
- return NullValue;
- var boolValue = (bool)value;
- return boolValue ? TrueValue : FalseValue;
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement