53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System;
|
|
using System.Windows.Data;
|
|
using System.Windows;
|
|
|
|
namespace DTS.Common.Converters
|
|
{
|
|
public class VisibilityToRowHeightConverter : DependencyObject, IValueConverter
|
|
{
|
|
/// <summary>
|
|
/// inverts the source prior to conversion
|
|
/// </summary>
|
|
public bool InvertSource
|
|
{
|
|
get => (bool)GetValue(InvertSourceProperty);
|
|
set => SetValue(InvertSourceProperty, value);
|
|
}
|
|
public static readonly DependencyProperty InvertSourceProperty =
|
|
DependencyProperty.Register("InvertSource", typeof(bool), typeof(VisibilityToRowHeightConverter), new PropertyMetadata(false));
|
|
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
if (value is Visibility vis)
|
|
{
|
|
if (InvertSource)
|
|
{
|
|
switch (vis)
|
|
{
|
|
case Visibility.Visible:
|
|
vis = Visibility.Collapsed;
|
|
break;
|
|
case Visibility.Hidden:
|
|
case Visibility.Collapsed:
|
|
vis = Visibility.Visible;
|
|
break;
|
|
}
|
|
}
|
|
if (vis == Visibility.Collapsed)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
//return parameter;
|
|
return parameter ?? 0;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|