wpf - WPF NumberTextBox 允许小数
问题描述
我遇到了 NumberTextBox 的问题。下面是 xaml 代码。
<cc:NumberTextBox
Margin="5,0,5,0"
HorizontalAlignment="Stretch"
IsEnabled="{Binding IsEditable}"
Style="{StaticResource TextBox_Default}"
TabIndex="25"
IsDecimalAllowed="True"
Text="{Binding ProductQuantity, ValidatesOnDataErrors=True, StringFormat={}{0:#.##}, UpdateSourceTrigger=PropertyChanged}" />
它应该允许用户在小数点后只输入 2 位数字。我尝试使用 StringFormat,但它无法正常工作。
示例:23.65567 它应该只允许用户输入 23.65
解决此问题的任何建议。提前致谢。
解决方案
首先,NumberTextBox 不是 WPF 的标准部分。您应该标记您用于该元素的任何库。那么你会在这里找到更多帮助。
此链接转到您可以编写自己的 NumberTextBox 的页面。至于数字限制,只需测试“点”并允许再按下两个键。
推荐阅读
- java - ProGuard - 混淆资源文件中的类名
- webpack - PhpStorm 无法识别使用 webpack 别名导入的 Sass 文件
- hibernate - 从 HibernateCompositeUserType 查询字段时出现 IllegalArgumentException
- android - 启用后台限制并允许应用程序在后台运行以进行长时间运行?
- sql - 乘以计数结果sql
- php - 使用 PHP 创建 Excel 文件
- javascript - react.js 的纯 JavaScript 语法
- visual-studio-code - vscode顶部的动线是什么,怎么去掉?
- android - 此构建中使用了已弃用的 Gradle 功能,使其与 Gradle 5.0 不兼容
- php - 如何连接两个查询结果并按列分组