You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/WPFExamples/Convertors/BoolToVisibilityConverter.cs

35 lines
1010 B

using System;
using System.Globalization;
using System.Windows;
namespace ZeroLevel.WPF
{
public sealed class BoolToVisibilityConverter : BaseConvertor<BoolToVisibilityConverter>
{
public Visibility TrueValue { get; set; }
public Visibility FalseValue { get; set; }
public BoolToVisibilityConverter()
{
TrueValue = Visibility.Visible;
FalseValue = Visibility.Collapsed;
}
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is bool))
return null;
return (bool)value ? TrueValue : FalseValue;
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (Equals(value, TrueValue))
return true;
if (Equals(value, FalseValue))
return false;
return null;
}
}
}

Powered by TurnKey Linux.