-
December 28th, 2009, 02:48 PM
#1
Opening a new window in a Windows Application
Hello!
I am using Visual Studio 2008 Pro. I have a WPF form and a button. When the user clicks the button, I want to open another window, which is more complex than a simple messagebox - it would query a database to get data and such.
So, what do I write in the
Code:
private void OpenTheOtherWindow_Click(object sender, RoutedEventArgs e)
{
//open window, please
}
procedure?
Surprisingly, I was not able to find anything on this topic anywhere on the net. All reference webish apps, but this is a Windows application.
Thanks!
-
December 28th, 2009, 04:06 PM
#2
Re: Opening a new window in a Windows Application
Originally Posted by EVS
All reference webish apps, but this is a Windows application.
this is not true.
http://www.google.com/search?hl=en&n...&aq=f&oq=&aqi=
http://social.msdn.microsoft.com/For...4-967a361cedd2
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
December 28th, 2009, 04:13 PM
#3
Re: Opening a new window in a Windows Application
You need to create a new Window in your application. Then, just .Show() it when you're ready to create an instance of it.
-
January 1st, 2010, 05:41 AM
#4
Re: Opening a new window in a Windows Application
That's all good, but the problem is that when I close the window and try to show it again, an exception is thrown saying that I cannot open a closing window. If I override the onclosing function and hide the window instead of closing it, the program wouldn't shut down, when I close the main window, because the other window has never been closed.... creating a new instance of the window object every time when I want to show it, wouldn't cut it as well, because then I cannot reference the window object from the main window as it is local to that button_click function.
I am using WPF.
-
January 1st, 2010, 06:45 AM
#5
Re: Opening a new window in a Windows Application
it's not easy to help you without seeing your masterpiece (you should already know that). so, what about posting some code?
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
-
January 1st, 2010, 03:13 PM
#6
Re: Opening a new window in a Windows Application
Assuming you want a modal dialog type of window, it's pretty simple if you use ShowDialog.
To make this even simpler when invoking the dialog, I typically create a static factory method. The code below shows an About dialog (which is a WPF window).
Code:
publicpartialclassAboutDlg : Window
{
publicstaticbool? ShowDialog( Window owner )
{
AboutDlg dlg = newAboutDlg( owner );
return dlg.ShowDialog( );
}
private AboutDlg( Window owner )
{
InitializeComponent( );
Owner = owner;
}
// other code here
}
The from another window, I call it like this:
Code:
privatevoid OnHelpAbout( object sender, RoutedEventArgs e )
{
AboutDlg.ShowDialog( this );
}
If you need to do something differently, then post your code so we can help you with it.
-
January 3rd, 2010, 12:34 PM
#7
Re: Opening a new window in a Windows Application
I'd like to have a window that would have a matrix which would be updated with data from an underlying database.
-
January 3rd, 2010, 03:50 PM
#8
Re: Opening a new window in a Windows Application
Originally Posted by EVS
I'd like to have a window that would have a matrix which would be updated with data from an underlying database.
We got that part. The question remains if whether you are looking for a modal dialog approach (as I've given you) or something else. What the window (or form) contains is irrelevent at this point if you are having trouble getting the window to display.
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
|