深圳网站制作公司兴田德润官网多少,陕西省建设工程质量监督局网站,现在网站开发模式,上海 建设工程质量监督站网站01—前言一个float或者double类型的数值#xff0c;如果小数点后0的个数≥4#xff0c;在界面上就会自动以科学计数法显示#xff0c;比如#xff1a;0.00003会显示成这样但是很多时候我并不希望它这样显示#xff0c;因为这样不方便编辑#xff0c;和界面其它数据格式也… 01—前言一个float或者double类型的数值如果小数点后0的个数≥4在界面上就会自动以科学计数法显示比如0.00003会显示成这样但是很多时候我并不希望它这样显示因为这样不方便编辑和界面其它数据格式也不统一我只希望原样显示。这时候我们就需要进行Convert。02—Converter实现方法首先创建Converter类public class StringToNumberConverter:IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){NumberStyles numberStyles System.Globalization.NumberStyles.Float;//使界面不显示科学计数法return Decimal.Parse(value.ToString(), numberStyles);}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){//可以输入“.”或者“,”原理是使其报错则不对binding的变量赋值string result (value.ToString().EndsWith(.) ? . : value).ToString();result (result.ToString().EndsWith(,) ? , : result).ToString();//可以输入末尾是0的小数原理同上Regex re new Regex(^([0-9]{1,}[.,][0-9]*0)$);result re.IsMatch(result) ? . : result;return result;}}其次在xaml中①引用命名空间xmlns:convertersclr-namespace:CaliburnTest②用户资源定义x:keyconverters:StringToNumberConverter x:KeyStringToNumberConverter/③在空间中绑定Converterdxlc:LayoutItemMargin10,0,0,0FontSize13LabelDefectSize(m) HorizontalContentAlignmentRightdxe:TextEditWidth150HorizontalAlignmentLeftMaskTypeNumericText{Binding DefectSize, UpdateSourceTriggerPropertyChanged, ModeTwoWay,Converter{StaticResource StringToNumberConverter}} //dxlc:LayoutItem03—运行结果成功实现数值的原样显示