using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
///
/// Represents the converter that converts Boolean values to and from Visibility enumeration values.
///
///
///
/// Use the BooleanToVisibilityConverter class to convert a Boolean to and from a Visibility value.
/// The Convert method returns Visibility.Visible when true is passed in
/// or Visibility.Collapsed when false is passed in.
/// Note that the Visibility.Collapsed value hides the control and does not reserve space for it in a layout.
/// When you call the ConvertBack method and specify a reference to an object, it returns true
/// if the object is Visible; otherwise, it returns false.
///
///
public class BooleanToVisibilityConverter : IValueConverter
{
///
/// Converts a Boolean value to a Visibility enumeration value.
///
/// The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.
/// This parameter is not used.
/// The converter parameter to use.
/// This parameter is not used.
/// The value to be passed to the target dependency property.
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var useFalseAsVisible = parameter != null && parameter.ToString().ToUpper() == "FALSE";
var hideNotCollapse = parameter != null && parameter.ToString().ToUpper() == "HIDE";
if (!useFalseAsVisible)
{
if ((bool)value)
return Visibility.Visible;
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
}
if ((bool)value)
return hideNotCollapse ? Visibility.Hidden : Visibility.Collapsed;
return Visibility.Visible;
}
///
/// Converts a Visibility enumeration value to a Boolean value.
///
/// A Visibility enumeration value.
/// This parameter is not used.
/// This parameter is not used.
/// This parameter is not used.
/// The value to be passed to the source object.
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}