zoukankan      html  css  js  c++  java
  • DecimalPercentageConverter

            <StackPanel x:Name="StackPanelPerson" Grid.Row="1" Width="200">
                <TextBox Text="{Binding Mode=TwoWay, Path=UnitPrice, ValidatesOnExceptions=True, NotifyOnValidationError=True, StringFormat=\{0:F\}}"/>
                <TextBox Height="23" Text="{Binding Mode=TwoWay, Path=UnitPriceRate, ValidatesOnExceptions=True, NotifyOnValidationError=True, Converter={StaticResource DecimalPercentageConverter}, StringFormat=\{0:P\}}" />
                <TextBox Text="{Binding Mode=TwoWay, Path=SuggestPrice, ValidatesOnExceptions=True, NotifyOnValidationError=True, StringFormat=\{0:F\}}"/>
                <TextBox Height="23" Text="{Binding Mode=TwoWay, Path=SuggestPriceRate, ValidatesOnExceptions=True, NotifyOnValidationError=True, Converter={StaticResource DecimalPercentageConverter}, StringFormat=\{0:P\}}" />
                <sdk:Label x:Name="LabelMessage" />
                <Button Content="test" Click="Button_Click_1" />
            </StackPanel>

         public class DecimalPercentageConverter : IValueConverter

        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                return value;
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (targetType != typeof(decimal) || value == null)
                    return value;

                string str = value.ToString();

                if (String.IsNullOrWhiteSpace(str))
                    return 0M;

                str = str.TrimEnd(culture.NumberFormat.PercentSymbol.ToCharArray());

                decimal result = 0M;
                if (decimal.TryParse(str, out result))
                {
                    result /= 100;
                }
                return result;
            }
        }
  • 相关阅读:
    总结
    PHP的重载-使用魔术方法实现
    用PHP实现一些常见的排序算法
    MySQL分组聚合group_concat + substr_index
    各种链接地址
    在Linux服务器上使用rz命令上传文件时时老报:Segmentation Fault,上传失败
    新安装的windows 10无法更新报0x80240fff错误的解决方案
    通过SSH key获取GitHub上项目,导入到IDEA中
    解压.zip,.tar.gz文件到指定目录,重命名文件
    byte字节数组的压缩
  • 原文地址:https://www.cnblogs.com/skydau/p/2633219.html
Copyright © 2011-2022 走看看