WPF的关于控件的只能输入数字的控件C1NumericBox

<c1:C1NumericBox Width="80" Style="{StaticResource StackPanel-C1MaskedTextBox-Multiple}" AllowNull="False" Minimum="0" Format="N2" Value="{Binding Item.DK,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

可以设置最小值和最大值,可以设置小数点位数N2就是2位小数点,另外样式由两种方式

<Label Content="DK值:" Style="{StaticResource ListSearch-Label}"/>

<c1:C1NumericBox Width="80" Style="{StaticResource StackPanel-C1NumericBox-Multiple}" AllowNull="False" Minimum="0" Format="N2" Value="{Binding Item.DK,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

列表中的小数位的字段显示也可以是使用Format="N2",这样就保留2位小数了

也可以写触发事件ValueChanged="MaterialIncreaseCost_ValueChanged",这样多字段直接可以相互读取和赋值

<Label Content="替换后加工成本增加金额:" Style="{StaticResource StackPanel-Label-130Multiple}" />

<c1:C1NumericBox Width="90" Style="{StaticResource StackPanel-C1NumericBox-Multiple}" AllowNull="True" Format="N2" Value="{Binding CurrentParamReviewItem.ProcessIncreaseCost,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="ProcessIncreaseCost" ValueChanged="MaterialIncreaseCost_ValueChanged" />

private void MaterialIncreaseCost_ValueChanged(object sender, C1.WPF.PropertyChangedEventArgs<double> e)

{

double? materialIncreaseCost = MaterialIncreaseCost.Value;

double? processIncreaseCost = ProcessIncreaseCost.Value;

if (!materialIncreaseCost.HasValue)

{

materialIncreaseCost = 0;

}

if (!processIncreaseCost.HasValue)

{

processIncreaseCost = 0;

}

double sum = materialIncreaseCost.Value + processIncreaseCost.Value;

double roundedSum = Math.Round(sum, 2, MidpointRounding.AwayFromZero);

// 现在你可以使用roundedSum变量了,比如更新UI或进行其他计算

// 例如,更新另一个控件的Text属性来显示结果

//TotalCost.Text = roundedSum.ToString("N2");

TotalCost.Value = roundedSum;

}

相关推荐
梁同学与Android几秒前
Android ---【经验篇】Fragment 生命周期高频面试题(附标准答案)
java·面试·fragment面试
吴佳浩 Alben1 分钟前
Python入门指南(五) - 为什么选择 FastAPI?
开发语言·python·fastapi
速易达网络2 分钟前
Java Web + Vue 前后端分离跨域解决方案
java·开发语言
艺杯羹3 分钟前
Thymeleaf模板引擎:让Spring Boot页面开发更简单高效
java·spring boot·后端·thymeleadf
小尧嵌入式3 分钟前
Linux进程线程与进程间通信
linux·运维·服务器·c语言·开发语言·数据结构·microsoft
武藤一雄6 分钟前
一款基于WPF开发的BEJSON转换工具
windows·c#·json·wpf
烂不烂问厨房7 分钟前
前端自适应布局之等比例缩放
开发语言·前端·javascript
小鸡吃米…8 分钟前
Python - 发送电子邮件
开发语言·python
SmoothSailingT11 分钟前
C/C++——结构体(Struct)
开发语言·c++·结构体·struct
大佬,救命!!!19 分钟前
python对应sql操作
开发语言·python·sql·学习笔记·学习方法