37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace Common.Converters
|
|
{
|
|
public class BooleanToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
bool input = value is bool b && b;
|
|
bool invert = parameter?.ToString()?.ToLower() == "invert";
|
|
|
|
if (invert)
|
|
input = !input;
|
|
|
|
return input ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
bool output = value is Visibility v && v == Visibility.Visible;
|
|
bool invert = parameter?.ToString()?.ToLower() == "invert";
|
|
|
|
if (invert)
|
|
output = !output;
|
|
|
|
return output;
|
|
}
|
|
}
|
|
}
|