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;

}

相关推荐
float_六七1 小时前
IntelliJ IDEA双击Ctrl的妙用
java·ide·intellij-idea
能摆一天是一天2 小时前
JAVA stream().flatMap()
java·windows
CodeCraft Studio3 小时前
PDF处理控件Aspose.PDF教程:使用 Python 将 PDF 转换为 Base64
开发语言·python·pdf·base64·aspose·aspose.pdf
零点零一3 小时前
VS+QT的编程开发工作:关于QT VS tools的使用 qt的官方帮助
开发语言·qt
颜如玉3 小时前
🤲🏻🤲🏻🤲🏻临时重定向一定要能重定向🤲🏻🤲🏻🤲🏻
java·http·源码
程序员的世界你不懂5 小时前
【Flask】测试平台开发,新增说明书编写和展示功能 第二十三篇
java·前端·数据库
星空寻流年5 小时前
设计模式第一章(建造者模式)
java·设计模式·建造者模式
lingchen19065 小时前
MATLAB的数值计算(三)曲线拟合与插值
开发语言·matlab
gb42152875 小时前
java中将租户ID包装为JSQLParser的StringValue表达式对象,JSQLParser指的是?
java·开发语言·python
一朵梨花压海棠go5 小时前
html+js实现表格本地筛选
开发语言·javascript·html·ecmascript