46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace JD.WPF.Converters
|
|
{
|
|
public class NullToVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
bool inverted = false;
|
|
if (parameter is bool)
|
|
inverted = (bool)parameter;
|
|
|
|
if(inverted)
|
|
return value == null ? Visibility.Visible : Visibility.Hidden;
|
|
else
|
|
return value == null ? Visibility.Hidden : Visibility.Visible;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
public class NullToVisibilityCollapsedConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
bool inverted = false;
|
|
if (parameter is bool)
|
|
inverted = (bool)parameter;
|
|
|
|
if (inverted)
|
|
return value == null ? Visibility.Visible : Visibility.Collapsed;
|
|
else
|
|
return value == null ? Visibility.Collapsed : Visibility.Visible;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|