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;
            }
        }
  • 相关阅读:
    VBA宏 合并EXCEL
    Opensource开源精神
    Redisd VS Memcached
    google-analytics.com
    Sybase PowerDesign 导入数据库结构formSqlserver
    Session Sticky About Nginx
    网站应用程式架构
    MapReduce形象总结
    Ubuntu升级内核
    ASP.NET5 MVC6入门教学之一(自己动手)
  • 原文地址:https://www.cnblogs.com/skydau/p/2633219.html
Copyright © 2011-2022 走看看