DictionaryValueAccessConverter<T> 类
- 程序集
- ClassIsland.Core.dll
用于在绑定中通过string类型的键访问以string为键,以T类型为值的字典的值的多项值转换器。
使用时需要以此抽象类为基类新建一个类,并将字典值的类型作为继承时的类型参数。(为什么不直接在XAML中传入泛型参数)
在转换时,第一个传入的绑定指向要访问的字典,第二个值指向要访问的键。如果获取值失败将返回 null。
此转换器不能反向转换。
public abstract class DictionaryValueAccessConverter<T> : IMultiValueConverter
类型参数
T
字典值类型
- 继承
-
DictionaryValueAccessConverter<T>
- 实现
- Derived
- 继承成员
方法
Convert(object[], Type, object, CultureInfo)
Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.
public object? Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
参数
values
object[]The array of values that the source bindings in the MultiBinding produces. The value UnsetValue indicates that the source binding has no value to provide for conversion.
targetType
TypeThe type of the binding target property.
parameter
objectThe converter parameter to use.
culture
CultureInfoThe culture to use in the converter.
返回
- object
A converted value.
If the method returns null, the valid null value is used.
A return value of DependencyProperty.UnsetValue indicates that the converter did not produce a value, and that the binding will use the FallbackValue if it is available, or else will use the default value.
A return value of Binding.DoNothing indicates that the binding does not transfer the value or use the FallbackValue or the default value.
ConvertBack(object, Type[], object, CultureInfo)
Converts a binding target value to the source binding values.
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
参数
value
objectThe value that the binding target produces.
targetTypes
Type[]The array of types to convert to. The array length indicates the number and types of values that are suggested for the method to return.
parameter
objectThe converter parameter to use.
culture
CultureInfoThe culture to use in the converter.
返回
- object[]
An array of values that have been converted from the target value back to the source values.