从窗口外更改var的值

本文关键字:var 的值 窗口 | 更新日期: 2023-09-27 18:29:28

在WPF上,我有打开form2 的窗口form 1

form2上,我有

 public partial class form2 : Window
    {
        public int temp1;
        public form2()
        {
            InitializeComponent();
            temp1 =123 ;
            this.tempTextBox.Text = temp1.ToString();
        }
    }

form1上,我想打开form2,但编辑temp1的值我想做的是:

    Window newWind = new form2();
    (newWind as form2).temp1=555;
    newWind.Show();

但当form 2打开时,我在tempTextBox=123 上看到

我想看看那里的555

请问我该怎么做?

谢谢!

从窗口外更改var的值

将其更改为属性,修改setter中的文本框文本。

private int _temp1;
public int temp1{
get { return _temp1; }
set { 
    _temp1= value; 
    this.tempTextBox.Text = value;
    }
}