WPF ShowDialog returns null immediately on second call

前端 未结 2 2010
猫巷女王i
猫巷女王i 2021-02-19 05:36

I think this is a bug in the WPF framework, without going into depths of my program and why I am doing what I am doing, I wrote a simple test application to prove my theory.

2条回答
  •  萌比男神i
    2021-02-19 05:44

    For anyone that has the same problem, here is how you can get around it:

    public App()
    {
        // Preserve and temporarily switch shutdown mode
        var oldShutdownMode = ShutdownMode;
        ShutdownMode = ShutdownMode.OnExplicitShutdown;
    
        var dialog = new Window();
        var result = dialog.ShowDialog();
        dialog = new Window();
        result = dialog.ShowDialog(); // This will show!
    
        // Reset shutdown mode to original value
        ShutdownMode = oldShutdownMode;    
    }
    

提交回复
热议问题