zoukankan      html  css  js  c++  java
  • WPF多路绑定

    WPF多路绑定
    多路绑定实现对数据的计算,XAML:
     
    引用资源所在位置
    xmlns:cmlib="clr-namespace:CommonLib;assembly=CommonLib">
    <UserControl.Resources>
            <cmlib:CustomMultiValueConvertor x:Key="MultiValueConverter"/>
    </UserControl.Resources>
     
    <TextBlock  Foreground="#FF7F7F7F" FontSize="22"  IsHyphenationEnabled="True" >
           <TextBlock.Text>
                  <MultiBinding Converter="{StaticResource MultiValueConverter}">
                          <Binding Path="OraElevatorData.shangyuegongzuorigonglvmidu" />
                          <Binding Path="OraElevatorData.benyuegongzuorigonglvmidu" />
                   </MultiBinding>
            </TextBlock.Text>
     </TextBlock>    
     
    用ValueConverter实现计算:
     
    public class CustomMultiValueConvertor : IMultiValueConverter
        {       
            public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                try
                {
                    if ((double)values[0] == 0)
                    {
                        return "--";
                    }
                    else
                    {
                        double bianhua = Math.Abs(((double)values[1] - (double)values[0]) / (double)values[0]);
                        string result = (bianhua * 100).ToString("0") + "%";
                        return result;
                    }
                }
                catch(Exception)
                {
                    return "--";
                }
            }
    
            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
            {
                return (value as string).Split(' ');
            }
        }
  • 相关阅读:
    L7-1 文本处理
    L6-14 继承多态
    L6-13 魔法方法
    L6-12 类的实例
    L6-11 综合运用
    L6-2 嵌套循环
    golang 关于引用类型
    golang close for channel
    go tip
    vscode官方文档
  • 原文地址:https://www.cnblogs.com/infly123/p/3765608.html
Copyright © 2011-2022 走看看