0
点赞
收藏
分享

微信扫一扫

WPF 转换器Converter 多值处理


定义多值处理方法。


using System;
using System.Globalization;
using System.Windows.Data;
namespace demo_business.Converters
{
public class NumIntervalConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        if (values == null || values.Length == 0)
        {
        return null;
        }
        //组装展示数据
        string value =  "数据拼接: "+ values[0].ToString() + values[1].ToString();

        return value;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

}
}

引用和使用

<Page x:Class="XXXXXXX.Views.Pages.XXXXXXXView"
      xmlns:localConverter="clr-namespace:demo.Converters" 
      mc:Ignorable="d" 
      Title="MainLeftBottomView">
    <Page.Resources>
        <localConverter:NumIntervalConverter x:Key="NumIntervalConverter"/>
    </Page.Resources>
      <Grid>
       <Label  Margin="20,0,0,0" >
                    <Label.Content>
                        <MultiBinding Converter="{StaticResource NumIntervalConverter}">
                            <Binding Path="OperationInfo.MinNum"/>
                            <Binding Path="OperationInfo.MaxNum"/>
                        </MultiBinding>
                    </Label.Content>
                </Label>
      </Grid>
</Page>
    

举报

相关推荐

0 条评论