WPF重写转换器

WPF重写转换器

为TextBlock重写转换器,保留一位小数

public class DoubleToString : IValueConverter
{
    #region IValueConverter 成员

        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if(value is double)
        {
            return ((double)value).ToString("f1");
        }
        return value;
    }

    object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
    #endregion
}
<hc:Window.Resources>
    <local:DoubleToString x:Key="ConverterDouble"/>
</hc:Window.Resources>
<TextBlock Text="{Binding ReadTemp, Converter={StaticResource ConverterDouble}}" Margin="0 5 10 5" HorizontalAlignment="Right" />

WPF重写转换器

上一篇:Windows 10当中如何添加开机启动应用


下一篇:第三章 Models模块属性详解