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重写转换器

原文:https://www.cnblogs.com/ycccq/p/13632840.html

以上是 WPF重写转换器[操作系统入门] 的全部内容, 来源链接: utcz.com/z/519325.html

回到顶部