devexpress 自带的Converts

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

将输入Booleannullable BooleanDefaultBoolean 值转换为任何类型的值。

<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 类型 (DefaultTrue and False) 和 nullable Boolean 类型 (nullTrue, and False).

 

ObjectToBooleanConverter

如果object 为 null, 返回 False; 否则返回 True.

 

StringToBooleanConverter

字符串为 Null 或 String.Empty, 返回False; 否则, 返回True

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值