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;
            }
        }
  • 相关阅读:

    入门动态规划问题
    AC自动机
    KMP算法
    [OpenGL]用鼠标拖拽图形移动
    HDU-2222 Keywords Search
    Trie
    Manacher算法
    linux环境搭建
    Android Studio使用JNI和NDK进行开发
  • 原文地址:https://www.cnblogs.com/skydau/p/2633219.html
Copyright © 2011-2022 走看看