首页 > 解决方案 > 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

解决此问题的任何建议。提前致谢。

标签: wpf

解决方案


首先,NumberTextBox 不是 WPF 的标准部分。您应该标记您用于该元素的任何库。那么你会在这里找到更多帮助。

此链接转到您可以编写自己的 NumberTextBox 的页面。至于数字限制,只需测试“点”并允许再按下两个键。

此链接是数字输入控件的开源集合


推荐阅读