前言
NumericUpDown控件可替代textbox控件方便用户输入值,但是wpf中无法直接使用NumericUpDown控件,必须借助第三方库来实现,本文就来讲解wpf中如何使用NumericUpDown控件
1、引用wpf.toolkit安装包



2、引用命名空间

3、使用控件
下面的代码中IntegerUpDown是用于输入整数的,DoubleUpDown是用于输入小数的,并且都有Minimum设置控件最小值,Maximum最大值,Increment是每次点击控件右边的向上或者向下箭头时增长或者减少的值。
csharp
<Window x:Class="wpf之NumericUpDown.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:wpf之NumericUpDown"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel Margin="20" Orientation="Vertical" >
<StackPanel Orientation="Horizontal" >
<TextBlock Text="年龄:" FontWeight="Bold"/>
<xctk:IntegerUpDown Value="{Binding Age}"
Minimum="0"
Maximum="150"
Increment="1"
Width="120"
/>
</StackPanel >
<StackPanel Orientation="Horizontal" >
<TextBlock Text="身高:" FontWeight="Bold" VerticalAlignment="Center" />
<xctk:DoubleUpDown Value="{Binding Quantity}"
Minimum="1"
Maximum="1000"
Increment="0.1"
Width="120"
/>
</StackPanel >
</StackPanel>
</Grid>
</Window>
4、运行效果
