ObjectToObjectConverter
类似于Map执行一对一映射
<UserControl ...
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<UserControl.DataContext>
<ViewModels:ViewModel State="Green"/>
</UserControl.DataContext>
<UserControl.Resources>
<dxmvvm:ObjectToObjectConverter x:Key="ColorStateToStringConverter">
<dxmvvm:MapItem Source="Red" Target="Ready"/>
<dxmvvm:MapItem Source="Yellow" Target="Steady"/>
<dxmvvm:MapItem Source="Green" Target="Go"/>
</dxmvvm:ObjectToObjectConverter>
</UserControl.Resources>
<Grid>
<TextBlock Text="{Binding State, Converter={StaticResource ColorStateToStringConverter}}"/>
</Grid>
</UserControl>
public enum ColorState { Red, Green, Yellow }
public class ViewModel {
public ColorState State { get; set; }
}
BooleanToObjectConverter
将输入Boolean、nullable Boolean或DefaultBoolean 值转换为任何类型的值。
<UserControl ...
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<UserControl.DataContext>
<ViewModels:ViewModel IsEnabled="True"/>
</UserControl.DataContext>
<UserControl.Resources>
<dxmvvm:BooleanToObjectConverter x:Key="BooleanToColorConverter">
<dxmvvm:BooleanToObjectConverter.TrueValue>
<SolidColorBrush Color="Green"/>
</dxmvvm:BooleanToObjectConverter.TrueValue>
<dxmvvm:BooleanToObjectConverter.FalseValue>
<SolidColorBrush Color="Red"/>
</dxmvvm:BooleanToObjectConverter.FalseValue>
</dxmvvm:BooleanToObjectConverter>
</UserControl.Resources>
<Grid>
<Border Background="{Binding IsEnabled, Converter={StaticResource BooleanToColorConverter}}"/>
</Grid>
</UserControl>
FormatStringConverter
在xaml中将输入的字符串进行 StringFormat 处理
<UserControl ...
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<UserControl.DataContext>
<ViewModels:ViewModel Price="32"/>
</UserControl.DataContext>
<UserControl.Resources>
<dxmvvm:FormatStringConverter x:Key="FormatStringConverter" FormatString="c"/>
</UserControl.Resources>
<Grid>
<TextBlock Text="{Binding Price, Converter={StaticResource FormatStringConverter}}"/>
</Grid>
</UserControl>
BooleanToVisibilityConverter
将Boolean 转换为Visibility
StringToVisibilityConverter
字符串为 Null 或 String.Empty, 返回 Visibility.Collapsed
; 否则, 返回Visibility.Visible
NumericToVisibilityConverter
数值为 0, 返回 False; 否则, 返回True
NumericToBooleanConverter
数值为 0, 返回 Visibility.Collapsed
; 否则, 返回Visibility.Visible
BooleanNegationConverter
反转输入布尔值或DefaultBoolean值。
DefaultBooleanToBooleanConverter
转换 DefaultBoolean 类型 (Default
, True
and False
) 和 nullable Boolean 类型 (null
, True
, and False
).
ObjectToBooleanConverter
如果object 为 null
, 返回 False
; 否则返回 True
.
StringToBooleanConverter
字符串为 Null 或 String.Empty, 返回False; 否则, 返回True