你好,
可以用Binding.StringFormat属性来指定一种现实格式,例如:
<TextBox Text="{Binding Value, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N2}}"/>
C#代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new Data();
}
}
public class Data
{
public int Value { get; set; }
}
下面有篇文章你可以参考:http://elegantcode.com/2009/04/07/wpf-stringformat-in-xaml-with-the-stringformat-attribute/
Sincerely,
Bob Bao [MSFT]
MSDN Community Support |
Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
