28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using System;
|
|
using System.Windows.Data;
|
|
|
|
namespace JD.WPF.Converters
|
|
{
|
|
public class StringToBooleanConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
if (!(value is string))
|
|
throw new ArgumentException("Converter value must be of type String");
|
|
if (!(parameter is bool))
|
|
throw new ArgumentException("Converter parameter must be of type Boolean");
|
|
|
|
string stringValue = (string)value;
|
|
bool invertTest = (bool)parameter;
|
|
if (string.IsNullOrEmpty(stringValue))
|
|
return invertTest ? true : false;
|
|
else
|
|
return invertTest ? false : true;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
throw new NotSupportedException("StringToVisibilityConverter does not support conversions from System.Windows.Visibility to String");
|
|
}
|
|
}
|
|
}
|