在DataGridNumericUpDownColumn上将字符串格式设置为无逗号

问题描述 投票:0回答:1

我使用设计框架mahapps.metro作为datagridnumericupdowncolumn:https://mahapps.com/controls/datagrid.html

有一个stringformat = C的例子。但我只需要D代替没有逗号的数字:string formats defined by microsoft

<Controls:DataGridNumericUpDownColumn Binding="{Binding DECIMAL_BINDING_VALUE}" StringFormat="D" Minimum="1" HideUpDownButtons="True"/>

绑定变量DECIMAL_BINDING_VALUE的默认值是12345.如果我打开窗口,Visual Studio将抛出异常:System.FormatException:“Format is invalid”。如果我使用String.Format = C我没有错误....

如何在XAML中使用DatagridNumericUpDownColumn为无逗号定义正确的StringFormat?

wpf xaml string-formatting mahapps.metro
1个回答
0
投票

尝试:

<Controls:DataGridNumericUpDownColumn Binding="{Binding DECIMAL_BINDING_VALUE, StringFormat='\{0:D\}'}" Minimum="1" HideUpDownButtons="True"/>

随着StringFormat内部的Binding

这就是它在BindingBase.StringFormat Property docs中的表现。

© www.soinside.com 2019 - 2024. All rights reserved.