using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
///
/// Represents the converter that converts Boolean values to and from width values.
///
///
///
/// Use the BooleanToColumnWidthConverter class to convert a Boolean to and from a width 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 abstract class BooleanToColumnWidthConverter : IValueConverter
{
public abstract double DefaultWidth { get; }
///
/// 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";
if (useFalseAsVisible)
{
if ((bool)value)
return 0D;
return DefaultWidth;
}
if ((bool)value)
return DefaultWidth;
return 0D;
}
///
/// 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;
}
}
public class DASTableBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 110D; }
}
public class ImportTestSetupBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 175D; }
}
public class ImportTestSetupISOCodeBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 140; }
}
public class ImportTestSetupISOChannelBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 190; }
}
public class LevelTriggerBooleanToColumnWidthConverter : BooleanToColumnWidthConverter
{
public override double DefaultWidth { get => 210D; }
}
}