按钮上的增量文本框值单击WPF C#

按钮上的增量文本框值单击WPF C#,c#,wpf,C#,Wpf,我试着做的是我有一个文本框,一个“-”和一个“+”按钮,点击按钮我需要减少/增加它的值。我在WPF方面有接近0的经验,我们在学校只学过控制台应用程序,现在我们完成了这个任务,我不知道为什么这个代码示例不起作用: using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows

我试着做的是我有一个文本框,一个“-”和一个“+”按钮,点击按钮我需要减少/增加它的值。我在WPF方面有接近0的经验,我们在学校只学过控制台应用程序,现在我们完成了这个任务,我不知道为什么这个代码示例不起作用:

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace sudokuGUI
{
   /// <summary>
   /// Interaction logic for MainWindow.xaml
   /// </summary>
   public partial class MainWindow : Window
   {
       public MainWindow()
       {
           InitializeComponent();
       }

       private void Button_Click(object sender, RoutedEventArgs e)
       {
           int ertek = Convert.ToInt32(textBox1.Text);
           if (ertek > 4)
           {
               textBox1.Text = $"{ertek--}";
           }
       }

       private void Button_Click_1(object sender, RoutedEventArgs e)
       {
           int ertek = Convert.ToInt32(textBox1.Text);
           if (ertek < 9)
           {
               textBox1.Text = $"{ertek++}";
           }
       }
   }
}
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
名称空间sudokuGUI
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
int-ertek=Convert.ToInt32(textBox1.Text);
如果(ertek>4)
{
textBox1.Text=$“{ertek--}”;
}
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
int-ertek=Convert.ToInt32(textBox1.Text);
如果(ertek<9)
{
textBox1.Text=$“{ertek++}”;
}
}
}
}

感谢您的帮助

ertek++
是一个很好的例子。
ertek++
的结果是操作前
ertek
的值

使用简单的
+
运算符:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
   int ertek = Convert.ToInt32(textBox1.Text);
   if (ertek < 9)
   {
       textBox1.Text = $"{ertek+1}";
   }
}
private void按钮\u单击\u 1(对象发送者,路由目标)
{
int-ertek=Convert.ToInt32(textBox1.Text);
如果(ertek<9)
{
textBox1.Text=$“{ertek+1}”;
}
}
ertek++
是一个很好的例子。
ertek++
的结果是操作前
ertek
的值

使用简单的
+
运算符:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
   int ertek = Convert.ToInt32(textBox1.Text);
   if (ertek < 9)
   {
       textBox1.Text = $"{ertek+1}";
   }
}
private void按钮\u单击\u 1(对象发送者,路由目标)
{
int-ertek=Convert.ToInt32(textBox1.Text);
如果(ertek<9)
{
textBox1.Text=$“{ertek+1}”;
}
}

对不起,正如我说的,我是一名学生,我还不太擅长编码,而且英语不是我的母语,但基本上什么也没发生。我没有得到任何例外或任何东西,文本框的内容基本上没有变化。当你点击按钮时,
textbox
的内容是什么?为什么不使用文本框来表示包含数字的文本框?大多数浏览器都有递增和递减的功能。@mm8“textBox1”(我需要更改的)的内容是4。所以基本上我只能在4到9之间,所以“-”按钮不能马上工作,但是“+”按钮应该可以,但是我上面描述的发生了(基本上没有发生)。对不起,正如我说的,我是一名学生,我还不太擅长编码,英语也不是我的母语,但基本上什么都没有发生。我没有得到任何例外或任何东西,文本框的内容基本上没有变化。当你点击按钮时,
textbox
的内容是什么?为什么不使用文本框来表示包含数字的文本框?大多数浏览器都有递增和递减的功能。@mm8“textBox1”(我需要更改的)的内容是4。所以基本上我只能在4到9之间,所以“-”按钮不能马上工作,但是“+”按钮应该可以,但是我上面描述的发生了(基本上没有)。它工作得很好,谢谢!我以为这些是可以互换的,但我猜我错了。它工作得很好,谢谢!我以为它们可以互换,但我猜我错了