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;
            }
        }
  • 相关阅读:
    【软件工程】Alpha冲刺 (6/6)
    【软件工程】Alpha冲刺 (5/6)
    为什么三层感知器能够解决任意区域组合的分类问题(不同隐层数的感知器的分类能力)
    PCA学习笔记(含推导过程)
    软件工程实践总结
    Beta冲刺(2/5)(麻瓜制造者)
    Beta冲刺(1/5)(麻瓜制造者)
    个人作业——华为软件开发云案例分析
    Alpha- 事后诸葛亮(麻瓜制造者)
    Alpha课堂展示(麻瓜制造者)
  • 原文地址:https://www.cnblogs.com/skydau/p/2633219.html
Copyright © 2011-2022 走看看