从此窗口分配字符串查询:
public partial class DB_conn_win : Window
{
public DB_conn_win()
{
InitializeComponent();
}
private void ask_DB_Click(object sender, RoutedEventArgs e)
{
string query = textBox1.Text();
}
.....
}
到主窗口
public partial class MainWindow : Window
{
string DB_query = DB_conn_win.query;
public MainWindow()
{
InitializeComponent();
.....
非常感谢您的帮助!
答案 0 :(得分:0)
public partial class DB_conn_win : Window
{
private void ask_DB_Click(object sender, RoutedEventArgs e)
{
this.Query = textBox1.Text();
}
public string Query;
.....
}
public partial class MainWindow : Window
{
string DB_query = DB_conn_win.query;
public SomeButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new DB_conn_win();
if (dialog.ShowDialog() == true)
{
this.DB_query = dialog.Query;
}
}
答案 1 :(得分:0)
public partial class DB_conn_win : Window {
public string query;
private void ask_DB_Click(object sender, RoutedEventArgs e) {
this.query = textBox1.Text();
}
}
public partial class MainWindow : Window {
string DB_query;
public MainWindow() {
InitializeComponent();
Loaded += Window_Loaded;
}
void Window_Loaded(object sender, RoutedEventArgs e) {
DB_conn_win dialog = new DB_conn_win();
dialog.Owner = this;
dialog.ShowDialog();
if (dialog.DialogResult != null && dialog.DialogResult.Value)
DB_Query = dialog.query;
}
}
ShowDialog和DialogResult检查取决于对话框的设置方式 - 有关详细信息,请参阅this link。