CODEKILLER

반응형

▶NULL 일 경우 Visibility 설정하는 Converter

 public class NullToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Visibility returnValue = Visibility.Visible;

        bool isEmpty = false;
        if ((value ?? "").Equals(""))
        {
            isEmpty = true;
        }

        if (isEmpty == true)
        {
            string param = parameter == null ? "" : parameter.ToString();
            switch (param.ToUpper())
            {
                case "":
                case "COLLAPSED":
                    returnValue = Visibility.Collapsed;
                    break;
                case "HIDDEN":
                    returnValue = Visibility.Hidden;
                    break;
            }
        }

        return returnValue;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band