33 lines
980 B
C#
33 lines
980 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace DMS.ValueConverts
|
|
{
|
|
public class NullableBooleanConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool b && parameter is string paramString)
|
|
{
|
|
if (bool.TryParse(paramString, out bool paramBool))
|
|
{
|
|
return b == paramBool;
|
|
}
|
|
}
|
|
return Binding.DoNothing;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool b && b && parameter is string paramString)
|
|
{
|
|
if (bool.TryParse(paramString, out bool paramBool))
|
|
{
|
|
return paramBool;
|
|
}
|
|
}
|
|
return Binding.DoNothing;
|
|
}
|
|
}
|
|
} |