Reputation: 1808
I'm new to WPF and have noticed that my application keeps running after I click the "X" button to exit the window. I've programmed GUI's before, so I know that this is common. However, when I look into the issue, whatever solutions I find do not seem to make any sense.
I've found this Applicaton.ShutdownMode solution, but it seems like I am not implementing it correctly. I want my application to shutdown "OnMainWindowClose". This is a question that is pretty much the same as mine that I don't think was explained clearly enough in the accepted answer.
Following the Application.ShutdownMode
solution, I have this in my MainWindow.xaml file:
<Window x:Class="CartToolsPrototype1.Window1" Background="White"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ResizeMode="CanMinimize"
Title="{DynamicResource CartTools}" Height="802" Width="950" WindowStartupLocation="CenterScreen" >
<Window.Resources>
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml"
ShutdownMode="OnMainWindowClose"
>
</Application>
The compiler gives me an error that says, "All objects added to an IDictionary must have a Key attribute or some other type of key associated with them." What exactly am I doing wrong here, and how can I correctly implement my shutdown function?
Thank you.
Upvotes: 1
Views: 2536
Reputation: 33364
You don't put Application
tag into your Window
. In your solution you have app.xaml
where you should put your:
ShutdownMode="OnMainWindowClose"
and quoting MSDN:
MainWindow is automatically set with a reference to the first Window object to be instantiated in the AppDomain.
Upvotes: 2