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;
            }
        }
  • 相关阅读:
    Levenshtein距离
    最长上升子序列
    python常用内置方法
    【转载】一个有趣的python排序模块:bisect
    python常用内置函数
    线性相位FIR系统的单位脉冲响应
    模拟信号与数字信号的傅里叶变换的关系
    从傅里叶级数到傅里叶变换
    完善实体类,由EF自动生成数据库过程中的一些问题
    成为NB程序员的“关键”
  • 原文地址:https://www.cnblogs.com/skydau/p/2633219.html
Copyright © 2011-2022 走看看