问题
I have an object that implements IMultiValueConverter
. It is used to bind visibility of a column based upon a particular permutation of a specific bool value and a specific enum value, both part of the bound data. The ConvertBack method self evidently has no meaning.
On a regular IValueConverter, I could return Binding.DoNothing, but that is not an object[]
so won't compile.
I currently throw an exception, but that doesn't feel ideal. Is there a better way?
回答1:
The correct way to implement the ConvertBack
method of an IValueConverter or an IMultiValueConverter that does not support back-conversion is to throw a NotSupportedException
.
Returning Binding.DoNothing
makes no sense, as the method should never be called anyway. But if it is ever called unexpectedly, you would rightly get an exception that tells you what went wrong.
public object[] ConvertBack(
object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
来源:https://stackoverflow.com/questions/50054267/correct-way-to-not-implement-convertback-on-a-imultivalueconverter