WPF C#怎么窗体间传值
我希望在点Bilishuru窗口里的btnO件后,能将输入的txtBili.Text的值传给Window1父窗口用于计算。所以在父窗口里定义了privatestringb...
我希望在点Bilishuru窗口里的btnO件后,能将输入的txtBili.Text的值传给Window1父窗口用于计算。所以在父窗口里定义了 private string bili; public string Bili,用于窗口传值,但点计算件btnCal_Click后,用到的bili值都是空的,并没有从Bilishuru传回来,想问问怎么改
子窗口代码如下:
public partial class Bilishuru : Window
{
public Bilishuru()
{
InitializeComponent();
}
public void btnO_Click(object sender, RoutedEventArgs e)
{
try
{
this.Close();
Window1 f1 = new Window1 ();
f1.Bili = this.txtBili.Text;
}
catch
{
MessageBox.Show("请输入float类型的数字");
}
}
父窗口代码:
private string bili;
public string Bili
{
get
{
return bili;
}
set
{
bili = value;
}
}
private void btnCal_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(bili );
DataRowView mySelectedElement = (DataRowView)listView.SelectedItem;
string fx = mySelectedElement.Row[3].ToString();
int fx1 = Convert.ToInt32(fx);
int bili2 = Convert.ToInt32(bili);
int peifangxishu =bili2 * fx1;
string b = peifangxishu.ToString();
MessageBox.Show(b);
} 展开
子窗口代码如下:
public partial class Bilishuru : Window
{
public Bilishuru()
{
InitializeComponent();
}
public void btnO_Click(object sender, RoutedEventArgs e)
{
try
{
this.Close();
Window1 f1 = new Window1 ();
f1.Bili = this.txtBili.Text;
}
catch
{
MessageBox.Show("请输入float类型的数字");
}
}
父窗口代码:
private string bili;
public string Bili
{
get
{
return bili;
}
set
{
bili = value;
}
}
private void btnCal_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(bili );
DataRowView mySelectedElement = (DataRowView)listView.SelectedItem;
string fx = mySelectedElement.Row[3].ToString();
int fx1 = Convert.ToInt32(fx);
int bili2 = Convert.ToInt32(bili);
int peifangxishu =bili2 * fx1;
string b = peifangxishu.ToString();
MessageBox.Show(b);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询