|
-
Mar 23rd, 2010, 07:29 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Close ('X') button no longer disposes of my form correctly
Hi All,
I'm not sure what happened but somehow my WPF forms application no longer disposes of itself properly from memory when clicking the 'X' button in the upper right corner. Everything was working fine and then one day it longer worked and I can't figure out why. I run the application and hit the close button and it still hangs as open (debugging) in visual studio.
Help!??? Please...
-
Mar 23rd, 2010, 11:16 AM
#2
Lively Member
Re: Close ('X') button no longer disposes of my form correctly
how are you calling the windows to show them? u need to provide a little more detail than that... and in the application settings(double click My Project in the solution explorer), what is the shutdown mode set to?
-
Mar 23rd, 2010, 12:17 PM
#3
Thread Starter
Addicted Member
Re: Close ('X') button no longer disposes of my form correctly
Hi,
The application is one main window with some dialog windows, so the main window launches as part of the application launch.
Here is the code for App.xaml
Code:
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ModernTech_Utilities_WPF.App"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!-- Resources scoped at the Application level should be defined here. -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Simple Styles.xaml"/>
<ResourceDictionary Source="ResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Currently it doesn't have a shutdownmode, although I have tried that and it did not work. A new application in wpf doesn't have that value either, I checked it on a dummy project.
Does this help? If not I can gladly provide more.
-
Mar 23rd, 2010, 12:30 PM
#4
Lively Member
Re: Close ('X') button no longer disposes of my form correctly
so ur saying u want ur app to close when ur mainwindow closes? You should be able to put that in the application settings like i said and it should close down. if not, try adding this to the windows code.
Code:
Private Sub Window1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
End
End Sub
-
Mar 23rd, 2010, 12:43 PM
#5
Thread Starter
Addicted Member
Re: Close ('X') button no longer disposes of my form correctly
Correct, when the user clicks the 'X' in the upper right corner of a default wpf window I want it to close and properly dispose of the application from memory. By default, if you create a new wpf forms application, it will do this.
Somehow I modified my current application so that it doesn't do that. As for the code above, it is VB and I am totally clueless in VB. I converted it and tried it using this code, and it doesn't work. Probably because handles is a support clause according to the converter.
Code:
public void MainWindow_Close(object sender, System.ComponentModel.CancelEventArgs e)
{
System.Environment.Exit(0);
}
Thanks!
-
Mar 23rd, 2010, 12:56 PM
#6
Lively Member
Re: Close ('X') button no longer disposes of my form correctly
oooo sorry, didnt realize that. Im not a c# guy but here what i came up with
put this in the constructor
Code:
this.Closing += new System.ComponentModel.CancelEventHandler(this.Window1_Closing);
then just add this to the window1 class
Code:
public void Window1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit;
}
-
Mar 23rd, 2010, 01:01 PM
#7
Thread Starter
Addicted Member
Re: Close ('X') button no longer disposes of my form correctly
Ok, so this got it to work... now the question is 'Why' did I need to do this when a new one doesn't require it??? Odd!
It's working for now and I can use it to do some application resource cleanup before exiting now as a bonus.
Thanks for the help!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|