Binding Visibility Converter in WPF C#

后端 未结 4 792
囚心锁ツ
囚心锁ツ 2020-12-21 02:39

I have a dependency property of type collection, when its callback fires based on the count I need to set the visibility of some of the controls on the screen.

But t

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-21 03:17

    Bool to visibility converter class

        public class BoolToVisibilityConverter : IValueConverter
            {
                public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
                {
                    return (bool)value ? Visibility.Visible : Visibility.Hidden;
                }
    
                public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
                {
                    throw new NotImplementedException();
                }
            }
    

    Xaml Changes mentioned below to show use of visibility converter class. A group box is used here to show the visibility. on change of radio button selection group box will be visible/hidden.

     
            
                
    
                
        
    

    In ViewModel use invokepropertychange than only you will get the visibility changes on your xaml.

    private Boolean isCustomerDetailChecked = false;
        public Boolean IsCustomerDetailChecked
        {
            get
            {
                return isCustomerDetailChecked;
            }
            set
            {
                isCustomerDetailChecked = value;
                InvokePropertyChanged("IsCustomerDetailChecked");
            }
        }
    

提交回复
热议问题