我在WPF中有一个MainWindow。如果我点击一个按钮,则执行此代码:在高级设置中保存过滤器
private void buttonAdvSett_Click(object sender, RoutedEventArgs e)
{
AdvancedSettingsWindow advancedSettingsPopup = new AdvancedSettingsWindow();
advancedSettingsPopup.ShowDialog();
}
将打开一个新窗口。在这个窗口中,我设置了一些过滤器(通过ComboBoxes)。如果我点击一个服装“确定”按钮,我想从组合框中保存字符串。
private void button_Click(object sender, RoutedEventArgs e)
{
// save the strings from the comboboxes if I click OK and close the window
this.Close();
}
我希望你能帮助我。 对不起,我的英语不好。英语不是我的母语。
祝您有美好的一天。
envy6
UPDATE:
这也为我工作: 在AdvancedSettingsWindow:
private void button_Click(object sender, RoutedEventArgs e)
{
Foo();
this.Close();
}
public event Action<string> Check;
public void Foo()
{
if(Check != null)
{
Check(methodINeedInMyMainWindow());
}
}
在我的主窗口:
private void buttonAdvSett_Click(object sender, RoutedEventArgs e)
{
AdvancedSettingsWindow advancedSettingsPopup = new AdvancedSettingsWindow();
advancedSettingsPopup.Check += value => labelCurrentFilterText.Content = value;
advancedSettingsPopup.ShowDialog();
}
来源:C# - Return variable from child window to parent window in WPF
为什么不公开这些值作为窗口的属性?您可以在窗口关闭后访问它们。如果窗口方式通过“确定”按钮或“取消”等关闭,您也可以存储。 – Onur
_save_是什么意思?你是否想将它保存到内存中,这样你就可以在应用程序的任何地方使用它,或者你想将它保存到一个文件中,以便在应用程序启动时加载它? – Pieter