111,097
社区成员




public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e) //打开
{
chuanzhi c = new chuanzhi();
c.c = this;
c.a = textBox1.Text; //传值成功,但实际问题中并不需要这种方法
c.Show();
}
private void button2_Click(object sender, RoutedEventArgs e) //修改
{
chuanzhi c = new chuanzhi();
c.c = this;
c.textBlock1.Text = textBox1.Text; //通过修改子窗口中的TextBlock中的值,未能达到效果
c.SetText(textBox1.Text) ; //通过调用子窗口的SetText方法也未能达到效果
}
}
public partial class SonWindow : Window
{
MainWindow _c; //为了给父窗口传值的定义
public MainWindow c
{
get
{
return this._c;
}
set
{
_c = value;
}
}
public string a;
public SonWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
textBlock1.Text = a;
}
public void SetText(string s)
{
textBlock1.Text = s;
}
}