简体   繁体   English

C#WPF-如何在按下按钮时更改文本块

[英]C# WPF - How to change a textblock when you press a button

I am trying to make it currently so that when i press lets say Button1 a textblock will change to a specific value. 我正在尝试使其当前,以便当我按让我说Button1时,一个文本块将更改为特定的值。 How i am trying to do this is like this: 我如何做到这一点是这样的:

    public MainWindow()
    {
        InitializeComponent();
        textResult.Text = currentValue.ToString();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        currentValue = 1;
    }

textResult is the textblock. textResult是文本块。

If i launch my program however it does not change. 如果我启动我的程序,它不会改变。

What am i doing wrong? 我究竟做错了什么?

 public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        currentValue = 1;
        textResult.Text = currentValue.ToString();
    }

You are not setting your TextBox's text property so you must do like as follow:- 您未设置TextBox的text属性,因此必须执行以下操作:

public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        currentValue = 1;
        textResult.Text = currentValue.ToString();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM