Files
DP44/Common/DTS.Common/Converters/BooleanToColumnWidthConverter.cs
2026-04-17 14:55:32 -04:00

85 lines
3.7 KiB
C#

using System;
using System.Windows;
using System.Windows.Data;
namespace DTS.Common.Converters
{
/// <summary>
/// Represents the converter that converts Boolean values to and from width values.
/// </summary>
///
/// <remarks>
/// Use the BooleanToColumnWidthConverter class to convert a Boolean to and from a width value.
/// The Convert method returns <see cref="Visibility.Visible">Visibility.Visible</see> when <b>true</b> is passed in
/// or <see cref="Visibility.Collapsed">Visibility.Collapsed</see> when <b>false</b> is passed in.
/// Note that the <see cref="Visibility.Collapsed">Visibility.Collapsed</see> 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 <b>true</b>
/// if the object is <see cref="Visibility.Visible">Visible</see>; otherwise, it returns <b>false</b>.
/// </remarks>
///
public abstract class BooleanToColumnWidthConverter : IValueConverter
{
public abstract double DefaultWidth { get; }
/// <summary>
/// Converts a Boolean value to a Visibility enumeration value.
/// </summary>
/// <param name="value">The Boolean value to convert. This value can be a standard Boolean value or a nullable Boolean value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the target dependency property.</returns>
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;
}
/// <summary>
/// Converts a Visibility enumeration value to a Boolean value.
/// </summary>
/// <param name="value">A Visibility enumeration value.</param>
/// <param name="targetType">This parameter is not used.</param>
/// <param name="parameter">This parameter is not used.</param>
/// <param name="culture">This parameter is not used.</param>
/// <returns>The value to be passed to the source object.</returns>
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; }
}
}