Where is the WPF Numeric UpDown control?

后端 未结 13 1823
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 00:02

Getting into the first serious WPF project. It seems like there are a lot of basic controls flat out missing. Specifically, I am looking for the Numeric UpDown control. W

13条回答
  •  遥遥无期
    2020-11-30 00:42

    I made my own;

    the xaml

    
        
        

    and the code behind

    private int _numValue = 0;
    
    public int NumValue
    {
        get {  return _numValue; }
        set
        {
            _numValue = value;
            txtNum.Text = value.ToString();
        }
    }
    
    public NumberUpDown()
    {
        InitializeComponent();
        txtNum.Text = _numValue.ToString();
    }
    
    private void cmdUp_Click(object sender, RoutedEventArgs e)
    {
        NumValue++;
    }
    
    private void cmdDown_Click(object sender, RoutedEventArgs e)
    {
        NumValue--;
    }
    
    private void txtNum_TextChanged(object sender, TextChangedEventArgs e)
    {
        if (txtNum == null)
        {
            return;
        }
    
        if (!int.TryParse(txtNum.Text, out _numValue))
            txtNum.Text = _numValue.ToString();
    }
    

提交回复
热议问题