标签:
原文:http://blog.csdn.net/kiss0622/article/details/5852153
1.父窗口代码
Window1.xaml.cs
private void Button_Click(object sender, RoutedEventArgs e) { Window2 w2 = new Window2(this.Top, this.Left);//this.Top,this.Left 作用是将当前父窗体的位置传给子窗体 if (w2.ShowDialog()==true) { text1.Text = w2.name; } } }
2.子窗口代码
Window2.xaml.cs
public string name; public Window2(double x,double y) { InitializeComponent(); //启用‘Manual’属性后,可以手动设置窗体的显示位置 this.WindowStartupLocation = WindowStartupLocation.Manual; this.Top = x; this.Left = y; } private void but1_Click(object sender, RoutedEventArgs e) { name = "hlr"; this.DialogResult = true; }
WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体
标签:
原文地址:http://www.cnblogs.com/xcsn/p/4462588.html