KeiStory

WPF BooleanToVisibilityConverter

 

xaml  단에서 bool 값에 따라서 visible 처리를 할 때 사용합니다.

    public class BooleanToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (true.Equals(value))
            {
                return Visibility.Visible;
            }

            if ("Hidden".Equals((parameter ?? "").ToString()))
            {
                return Visibility.Hidden;
            }

            return Visibility.Collapsed;
        }

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

 

반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band