本文讲解C#WPF控件Textbox绑定浮点型数据限制小数位方法。
XAML中,使用StringFormat来格式化TextBox的文本
- <Window x:Class="WpfApp.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:WpfApp"
- mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
- <Window.DataContext>
- <local:MyViewModel />
- Window.DataContext>
- <Grid>
- <TextBox Text="{Binding Number, StringFormat={}{0:N2}}" Width=