WPF Trigger not null

前端 未结 3 559
深忆病人
深忆病人 2021-02-06 14:49

How to trigger an action in WPF when the Property is not null? This is a working solution when is null:

         


        
3条回答
  •  花落未央
    2021-02-06 15:16

    it is an old question, but I want to answer. Actually you can. Just you have to use Converter in binding. Converter must return is null or not. So you will check statement is true or false. It provide you can check two condition if return value is false, it means it is not null. If it is true, it means it is null.

    
    
    
    
    
        public class IsNulConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
    
            return value == null;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
    
            return Binding.DoNothing;
        }
    }
    

提交回复
热议问题