c# - 在模式对话框关闭时更新父页面?

标签 c# .net wpf

我有一个带有网格的窗口。该窗口有一个按钮,当按下该按钮时,将显示一个模态对话框。

代码:

    private void Edit_Click6S(object sender, RoutedEventArgs e)
    {
        TextEditWindow editWindow = new TextEditWindow();
        editWindow.ShowDialog();
    }

当用户完成此对话框时,将调用以下代码:

    Window.Close()

但是父窗口的网格没有更新。关闭子对话框时,有没有办法重新初始化父窗口网格?是吗,怎么样?

最佳答案

由于对话框在关闭之前会阻止执行,因此您可以在 ShowDialog() 调用后直接填充网格:

private void Edit_Click6S(object sender, RoutedEventArgs e)
{
    TextEditWindow editWindow = new TextEditWindow();
    editWindow.ShowDialog();
    PopulateGrid();
}

否则你可以处理对话框的关闭事件

editWindow.Closed += dialog_Closed;    

private void dialog_Closed(object sender, System.EventArgs e)
{
    PopulateGrid();
}

关于c# - 在模式对话框关闭时更新父页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11969574/

相关文章:

c# - 未找到 Web Api Content.ReadAsAsync 方法,但代码编译

c# - 经验丰富的 C++ 尝试 C#

c# - Azure 表存储 SDK - 清空表

c# - 为什么隐式使用 ToString() 不会导致异常?

c# - 我想在 Excel 中将 2000 个数据单元格与 3000 个其他数据单元格进行比较,但这需要很长时间

c# - 返回 MS.InternalMemoryStream 的简单网络客户端请求

c# - "Input string was not in a correct format."

c# - ItemsControl.GetContainerForItemOverride 有什么用?

css - WPF 中的级联样式(a la CSS)

wpf - 有没有一种简单的方法在xaml中指定int值