Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom WPF dialog window causes shell window to close immediately after .Show called
    primarykey
    data
    text
    <p>OK. A bit of setup. </p> <p>I have a small PRISM based app using Unity. </p> <p>I created a class (separate from the main program where the shell window is) that contains it's own WPF window to pop up as a dialog box while an update is running.</p> <p>The class does some file copying (real simple stuff just as a PoC) and the window updates the user to its progress.</p> <p>The window is shown modally (.ShowDialog();) so that it blocks the thread while the update runs.</p> <p>The update is run off of the ContentRendered event.</p> <p>When the update finishes, .Close() is called on the window.</p> <p>This class is instantiated and the update process started (by calling a public function on the class called StartUpdate()), in the OnStartup event in the main program's App.xaml.cs file.</p> <p>After that, a bootstrapper is created and run.</p> <p>Finally, in the bootstrapper class, some modules are loaded (they don't do anything except for register a view), and the shell window is resolved and shown in the override of InitializeShell. </p> <p>All pretty standard stuff, except that the program just closes after it exits InitializeShell. If I don't call .Close in the updater class and let the user close the custom dialog with the X, the same thing happens. I also tried showing the dialog in a non-modal way (just .Show()) and the rest of the program works fine. However, the process does not block so the update would happen after or while the main program loaded. And that would be pointless. I have found a few ways around this. I'm just curious if anyone can explain the behavior.</p> <p><strong>Edit: An example code snippet:</strong> When the user closes the Window1 window, the MainWindow never loads.</p> <pre><code>/// &lt;summary&gt; /// Interaction logic for App.xaml. This is where the program starts. /// &lt;/summary&gt; public partial class App : Application { private void Application_Startup(object sender, StartupEventArgs e) { dialogWPF.Class1 c = new dialogWPF.Class1(); c.Update(); //After this, the program should continue as normal (Open the MainWindow window) } } /// &lt;summary&gt; /// This is the code for Class1 that is called in App.xaml.cs /// &lt;/summary&gt; public class Class1 { private Window1 _win; public Class1() { _win = new Window1(); } public void Update() { _win.ShowDialog(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload