Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I have mainwindow that has a button. when I click the button it should show a new form but will remain at the same window? Should I show the new window and hide the previous one or there is another way to do this? the application is full screened, written in vb.net.

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 18-Aug-13 3:13am    
What does it mean: "show a new form but will remain at the same window?"?
—SA
hoyice 18-Aug-13 3:39am    
I am creating a kiosk application in WPF. There should be only one window opened but whenever a button is clicked the design and the content of the window should change. In windows form application it just form.show and form.hide, i don't know how to run it in WPF.
hoyice 18-Aug-13 3:41am    
I have already read your solution, but i don't know how to do that. do you have tutorial links in which i could follow?
Sergey Alexandrovich Kryukov 18-Aug-13 3:43am    
What tutorial? I already explained everything. If something is unclear, I'll gladly provide some more detail, just ask your follow-up questions...

All you need to know is already described in WPF tutorials and documentation. Well, I just don't know which part of WPF you need to understand better. Maybe, this is layout; then try to read on layout model of WPF. There is a number of aspects you need to understand, but by far, not all of WPF...

—SA
hoyice 18-Aug-13 4:12am    
you mean, i don't need to code for button_click handler event? how am i able to show a different user interface if i click a button? I'm lost.

1 solution

All ways of showing a new window instead of the main one are questionable, to say the least. You cannot make a new window a main window. (In fact you can, but it is also problematic, let's talk about it later.)

First of all, which window is main is defined by the parameter passed to Application.Run(Window). The problem of your approach is that you have your main window hidden. So, when you close some other window, the application won't actually close. It can be closed if you close the main window. To work around it, you would need, for example, to override virtual the method System.Windows.Window.OnClosed to call Application.Shutdown. It actually depends on what you want.

I understand, you probably need wizard-like behavior, when one kind of window replace another one. Another way of doing so would be calling Application.Run(Window) several times, each time with different window. Normally, this code is auto-generated. You will need to remove main application XAML and write your own entry point method for such behavior of Application.

All such work-around approaches will work, but…

I don't think it would make a whole lot of sense. I think that the best pattern is to have only one window for all application. (I don't count some windows to be used as modal dialogs, you can have some.) You can change the appearance of such (always main) window depending on the UI state. Let's consider the wizard-like behavior of application. It simply mean that you have a line (list) of different "windows" which you can visit in forward direction and sometime go backward. Let me call those sequential windows "frames". They all usually share some buttons (and/or something else). If so, do the following: on your (main) window create, say, a panel for buttons and several panel each representing one frame. As you need only one frame at a time, make all those panels hidden and only one visible. Populate each of such frame panels with the content you planned earlier to be placed on a separate window. Now, as you navigate through the sequence of frames, hide all of them except the one which is needed on a given step.

This is easy and will give you much less problems as with separate windows.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900