<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The WPF Application Class: Overview and Gotcha</title>
	<atom:link href="http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/</link>
	<description>Trapped online since 2004</description>
	<lastBuildDate>Wed, 11 Jan 2012 10:22:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Miral</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-760</link>
		<dc:creator>Miral</dc:creator>
		<pubDate>Fri, 08 Apr 2011 00:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-760</guid>
		<description>I&#039;m pretty sure that the &quot;correct&quot; solution in this case is to set the ShutdownMode to Explicit before creating your login window, and then set it back to either OnLastWindowClose or OnMainWindowClose *after* creating (and possibly also showing) your main window.</description>
		<content:encoded><![CDATA[<p>I&#8217;m pretty sure that the &#8220;correct&#8221; solution in this case is to set the ShutdownMode to Explicit before creating your login window, and then set it back to either OnLastWindowClose or OnMainWindowClose *after* creating (and possibly also showing) your main window.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jl</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-759</link>
		<dc:creator>jl</dc:creator>
		<pubDate>Sat, 19 Mar 2011 02:26:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-759</guid>
		<description>

public class MyApp : Application
{
    protected override void OnStartup(object sender, StartUpEventArgs e)
    {
        if (firstRun)
        {
            MyConfigDialog dialog = new MyConfigDialog();
            if (!dialog.ShowDialog().Value)
            {
                this.Shutdown();
            }
        }
        MyMainWindow window = new MyMainWindow();
        //guess what? this doesn&#039;t work!
        this.MainWindow = window;
        window.Show();
    }
}
I’m seriously baffled by this. Looking around in Reflector, the code I’m looking at says it shouldn’t act like this. I also don’t touch Application.ShutdownMode (I’ve tested this with OnLastWindowClose and with OnMainWindowClose). 





I think the problem with this one has to do with the window count as well as the MainWindow property.  As you noticed with the first example posted, showing a dialog and closing it causes the app to shut down as the MainWindow property is nulled.  The same is happening here, and if you do happen to change the ShutdownMode to OnLastWindowClose, you get essentially the same behavior, because the first window (the dialog) is opened, and then the last window (the dialog) is closed (shutting down the app), before the next window is instantiated.  I haven&#039;t tested, but would be willing to bet that if you set the ShutdownMode to Explicit, you would not get this (not neccessarily recommended, just saying...)


All that said, many thanks for the post.  As a relative newbie to any programming other than VBA, this got me really digging around in WPF application lifetime management.  If you like, I can post the MSDN links where I found this info (along with many other related and quite helpful topics).

Cheers and thanks again,
j.</description>
		<content:encoded><![CDATA[<p>public class MyApp : Application<br />
{<br />
    protected override void OnStartup(object sender, StartUpEventArgs e)<br />
    {<br />
        if (firstRun)<br />
        {<br />
            MyConfigDialog dialog = new MyConfigDialog();<br />
            if (!dialog.ShowDialog().Value)<br />
            {<br />
                this.Shutdown();<br />
            }<br />
        }<br />
        MyMainWindow window = new MyMainWindow();<br />
        //guess what? this doesn&#8217;t work!<br />
        this.MainWindow = window;<br />
        window.Show();<br />
    }<br />
}<br />
I’m seriously baffled by this. Looking around in Reflector, the code I’m looking at says it shouldn’t act like this. I also don’t touch Application.ShutdownMode (I’ve tested this with OnLastWindowClose and with OnMainWindowClose). </p>
<p>I think the problem with this one has to do with the window count as well as the MainWindow property.  As you noticed with the first example posted, showing a dialog and closing it causes the app to shut down as the MainWindow property is nulled.  The same is happening here, and if you do happen to change the ShutdownMode to OnLastWindowClose, you get essentially the same behavior, because the first window (the dialog) is opened, and then the last window (the dialog) is closed (shutting down the app), before the next window is instantiated.  I haven&#8217;t tested, but would be willing to bet that if you set the ShutdownMode to Explicit, you would not get this (not neccessarily recommended, just saying&#8230;)</p>
<p>All that said, many thanks for the post.  As a relative newbie to any programming other than VBA, this got me really digging around in WPF application lifetime management.  If you like, I can post the MSDN links where I found this info (along with many other related and quite helpful topics).</p>
<p>Cheers and thanks again,<br />
j.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spinatose</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-758</link>
		<dc:creator>spinatose</dc:creator>
		<pubDate>Mon, 28 Feb 2011 20:54:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-758</guid>
		<description>Spent most of the day trying to find a solution to the same problem. Thanks for posting this!</description>
		<content:encoded><![CDATA[<p>Spent most of the day trying to find a solution to the same problem. Thanks for posting this!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daeD</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-676</link>
		<dc:creator>daeD</dc:creator>
		<pubDate>Fri, 11 Dec 2009 14:28:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-676</guid>
		<description>thanks a lot, I was looking for that for some time :)</description>
		<content:encoded><![CDATA[<p>thanks a lot, I was looking for that for some time <img src='http://www.ageektrapped.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ondrej Gratz</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-673</link>
		<dc:creator>Ondrej Gratz</dc:creator>
		<pubDate>Fri, 06 Nov 2009 14:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-673</guid>
		<description>Great ! This article was useful for me, too.</description>
		<content:encoded><![CDATA[<p>Great ! This article was useful for me, too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ciantic</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-670</link>
		<dc:creator>Ciantic</dc:creator>
		<pubDate>Thu, 08 Oct 2009 20:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-670</guid>
		<description>I&#039;m sorry above example works just fine.

Just remember to *remove* the StartupUri in Application element at app.xaml.

I was in a hurry and missed that. (Looking only the source code)</description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry above example works just fine.</p>
<p>Just remember to *remove* the StartupUri in Application element at app.xaml.</p>
<p>I was in a hurry and missed that. (Looking only the source code)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ciantic</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-669</link>
		<dc:creator>Ciantic</dc:creator>
		<pubDate>Thu, 08 Oct 2009 18:40:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-669</guid>
		<description>Something is changed, or was not working all along:

public class MyApp : Application
{
    protected override void OnStartUp(object sender, StartUpEventArgs e)
    {
        MainWindow window = new MainWindow();
        MyConfigDialog dialog = new MyConfigDialog();
        dialog.ShowDialog();
        
        // Problem: The application doesn&#039;t close when mainwindow is closed.
        // window.Show();  // If you uncomment this it shows *two* main windowes. But same problem, application never closes.
    }
}</description>
		<content:encoded><![CDATA[<p>Something is changed, or was not working all along:</p>
<p>public class MyApp : Application<br />
{<br />
    protected override void OnStartUp(object sender, StartUpEventArgs e)<br />
    {<br />
        MainWindow window = new MainWindow();<br />
        MyConfigDialog dialog = new MyConfigDialog();<br />
        dialog.ShowDialog();</p>
<p>        // Problem: The application doesn&#8217;t close when mainwindow is closed.<br />
        // window.Show();  // If you uncomment this it shows *two* main windowes. But same problem, application never closes.<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zsombor</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-629</link>
		<dc:creator>Zsombor</dc:creator>
		<pubDate>Sun, 03 May 2009 17:33:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-629</guid>
		<description>Great! 
Anyway it&#039;s not the solution of mine because I have to reopen the first and second window as well several times.
So my solution is exactly what Torna wrote!
Thank you for shaing the info. You saved me maybe hours :)</description>
		<content:encoded><![CDATA[<p>Great!<br />
Anyway it&#8217;s not the solution of mine because I have to reopen the first and second window as well several times.<br />
So my solution is exactly what Torna wrote!<br />
Thank you for shaing the info. You saved me maybe hours <img src='http://www.ageektrapped.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brenda</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-609</link>
		<dc:creator>Brenda</dc:creator>
		<pubDate>Tue, 10 Mar 2009 16:08:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-609</guid>
		<description>Where does the variable &#039;firstRun&#039; get set? Everything else works great. Thanks!</description>
		<content:encoded><![CDATA[<p>Where does the variable &#8216;firstRun&#8217; get set? Everything else works great. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Torna</title>
		<link>http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/comment-page-1/#comment-607</link>
		<dc:creator>Torna</dc:creator>
		<pubDate>Mon, 02 Mar 2009 10:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ageektrapped.com/blog/the-wpf-application-class-overview-and-gotcha/#comment-607</guid>
		<description>set shutdown mode to explicit on application</description>
		<content:encoded><![CDATA[<p>set shutdown mode to explicit on application</p>
]]></content:encoded>
	</item>
</channel>
</rss>

