add PartialConverter
This commit is contained in:
1 parent
1d9f0de409
commit
6a433b8cef
1 file changed
+35
@@ -0,0 +1,35 @@
|
||||
using bts.utils;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
/// <summary>
|
||||
/// This converter expects the first item in the values array to be either an IValueConverter, or an IMultiValueConverter,
|
||||
/// then pipes the subequent value(s) into said converter's Convert method and returns the result.
|
||||
/// </summary>
|
||||
class PartialConverter : IMultiValueConverter {
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
|
||||
switch (values.Length) {
|
||||
case 0:
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
if (values[0] is IValueConverter cv)
|
||||
return cv.Convert(values[1], targetType, parameter, culture);
|
||||
break;
|
||||
default:
|
||||
if (values[0] is IMultiValueConverter mvc) {
|
||||
ArrayHelper.remove_at(ref values, 0);
|
||||
return mvc.Convert(values, targetType, parameter, culture);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return new ValidationResult(false, null);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) =>
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user