CODEKILLER

반응형

▶ 인자로 int형을 넘겨서 Visible 처리하는 Converter

public class IntToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        int integer = (int)value;
        if (integer == int.Parse(parameter.ToString()))
            return Visibility.Visible;
        else
            return Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return parameter;
    }
}

public class ReverseIntToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        int integer = (int)value;
        if (integer != int.Parse(parameter.ToString()))
            return Visibility.Visible;
        else
            return Visibility.Collapsed;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return parameter;
    }
}

▶xaml에서의 사용

: ConverterParameter에 int형을 넘겨서 Visibility를 설정합니다.

<Button Visibility="{Binding Path=IsBtnVisible, Converter={StaticResource IntToVisibilityConverter}, ConverterParameter=1}" />

 

반응형

공유하기

facebook twitter kakaoTalk kakaostory naver band