Why do I get a DependencyProperty.UnsetValue when converting a value in a MultiBinding?

后端 未结 3 1448
闹比i
闹比i 2020-12-11 00:10

I have an extremely simple IMultiValueConverter that simply OR\'s two values. In the example below, I want to invert the first value using an equally simple boolean inverter

3条回答
  •  一生所求
    2020-12-11 00:27

    Just in addition to all other answers, I usually add these lines to the beginning of Convert method:

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Any(x => x == DependencyProperty.UnsetValue))
                return DependencyProperty.UnsetValue;
    
            ...
    
        }
    

    to make sure that none of the values is unset (that usually happens with DataGrid with CanUserAddRows="True").

提交回复
热议问题