wpf中调用NumericUpDown控件

前言

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、运行效果

马工撰写的年入30万+C#上位机项目实战必备教程(点击下方链接即可访问文章目录)

1、《C#串口通信从入门到精通》

2、《C#与PLC通信从入门到精通 》

3、《C# Modbus通信从入门到精通》

4、《C#Socket通信从入门到精通 》

5、《C# MES通信从入门到精通》

6、《winform控件从入门到精通》

7、《C#操作MySql数据库从入门到精通》

相关推荐
Scout-leaf2 天前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户298698530142 天前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools3 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的4 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21884 天前
.NET 本地Db数据库-技术方案选型
windows·c#
lindexi4 天前
dotnet DirectX 通过可等待交换链降低输入渲染延迟
c#·directx·d2d·direct2d·vortice
qq_454245034 天前
基于组件与行为的树状节点系统
数据结构·c#
bugcome_com4 天前
C# 类的基础与进阶概念详解
c#
雪人不是菜鸡4 天前
简单工厂模式
开发语言·算法·c#
铸人4 天前
大数分解的Shor算法-C#
开发语言·算法·c#