C#WPF-如何在按下按钮时更改文本块
我正在尝试当前设置,以便当我按下lets say Button1时,文本块将更改为特定值。我是如何做到这一点的:C#WPF-如何在按下按钮时更改文本块,c#,wpf,xaml,C#,Wpf,Xaml,我正在尝试当前设置,以便当我按下lets say Button1时,文本块将更改为特定值。我是如何做到这一点的: public MainWindow() { InitializeComponent(); textResult.Text = currentValue.ToString(); } private void Button_Click(object sender, RoutedEventArgs e) {
public MainWindow()
{
InitializeComponent();
textResult.Text = currentValue.ToString();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
currentValue = 1;
}
textResult是textblock
如果我启动我的程序,但它不会改变
我做错了什么?您没有设置文本框的文本属性,因此您必须按如下操作:-
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
currentValue = 1;
textResult.Text = currentValue.ToString();
}
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
currentValue = 1;
textResult.Text = currentValue.ToString();
}
您没有设置TextBox的text属性,因此必须执行以下操作:-
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
currentValue = 1;
textResult.Text = currentValue.ToString();
}
使用绑定,文本块的文本属性与currentValue属性,使用绑定,文本块的文本属性与currentValue属性,