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;

}

相关推荐
无敌最俊朗@13 小时前
STL-list面试剖析(面试复习4)
开发语言
bing.shao13 小时前
Golang 之 defer 延迟函数
开发语言·后端·golang
无敌最俊朗@13 小时前
Qt 多线程编程: moveToThread 模式讲解
java·开发语言
!停13 小时前
深入理解指针(4)
开发语言·javascript·ecmascript
小白狮ww13 小时前
Matlab 教程:基于 RFUAV 系统使用 Matlab 处理无人机信号
开发语言·人工智能·深度学习·机器学习·matlab·无人机·rfuav
penngo13 小时前
Golang使用Fyne开发桌面应用
开发语言·后端·golang
程序员清风13 小时前
别卷模型了!上下文工程才是大模型应用的王道!
java·后端·面试
go__Ahead13 小时前
【Java】ThreadLocal源码解析
java
利剑 -~14 小时前
Spring AI Alibaba 1.1版本
java·人工智能·spring
雨中飘荡的记忆14 小时前
Guava工具库实战
java