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" />