I am new to desktop application development and have a pretty basic question. I have a WPF form named MainWindow, how should I go about having multiple pages on this, such as "User Management", "Manage Content" etc..
I think I have the following options:
Use multiple forms
Tabs
Group Box?
Any clarification would be great!
Well in my most recent application I started by using a TabControl, that's a safe and rather easy way to go.
Recently switched the tabcontrol with a StackPanel with a series of Expanders inside. I styled the expanders to have them display the header vertically and expand horizontally... somewhat similar to the first xbox dashboard. And it looks and works great! =)
Another alternative would be to use a Page instead of a window... Then you would just have to Navigate to each different page.
EDIT:
Here's an example of a multi-page application... might be close to what you need.
The solution I went with that suited what I was looking for was using WPF Pages but thanks for your answers.
There are many ways to do that, such as creating UserControl and show them in the run time.But using TabControl is fast and safe.
Just Use TabControl and place your pages in tab items .Then hide the header of TabControl by setting the value Visibility="Collapsed" to each TabItem.
The result is as below:
As you see the headers are hide and you can switch to each page you want.
Create
usercontrol(wpf): UserManagement
usercontrol2(wpf) : ManageContent
place control "ContentControl" in the main window
Run the code on click of button:
//Displays usercontrol1
contentControl.content = new UserManagement();
//Displays usercontrol2
contentControl.content = new ManageContent();
Hope this helps you.
I'd like to give you an example of something I have in one of my applications.
The app has two windows: the main window and another one (also derived from Window and equipped with the appropriate buttons and event handlers) that is used as a start dialog. The start dialog is called in the constructor of the main window like this:
public partial class MainWindow : Window
{
startdlg m_dlg;
// ...
public MainWindow()
{
m_dlg = new startdlg();
if ((bool)m_dlg.ShowDialog())
{
// ...
}
else
{
Close();
}
// ...
Related
I'm working on a project in WPF and I'm not really familiar with it.
I have built the program, but I'm dissatisfied with the navigation.
It's a simple program, a couple of buttons which takes you to different pages. Changing page have I solved by the following:
Menu main = new Menu();
App.Current.MainWindow = main;
this.Close();
main.Show();
This is probably very incorrect. Any knowledge of standard practice for code behind or MVVM?
I had a project where i used the standard method Visibilty and changed it between collapsed and visible.
So three pages => 3 Containers
Button1
-- Show Container1 Collapse Container2,3
Button2
-- Show Container2 Collapse Container1,3
Button3
-- Show Container3 Collapse Container1,2
If you have a lot of pages this is not a nice way to do it, but for 2 to 5 pages its ok.
You could take a look at Paul Stovell's blog post for more information about the common navigations options that are available in WPF: http://paulstovell.com/blog/wpf-navigation
You could implement an interface in the view where the Frame is defined and then inject the view model with this interface to be able to use the Frame for navigation. There is an example available here: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b09bbfd4-05ee-4f62-b5df-77c0792e6ad7/how-to-refresh-the-frame-using-a-view-model-in-c?forum=wpf
Warning! This is noob question probably! Sorry in advance.
I'm learning C# (using MS Studio 2013) and I'm having hard time creating some kind of decent navigation in simple desktop program.
Basically what I want is this: MenuStrip with options like "calculate something", "Calculate somethingelse"... and other (that I can easily add later - like dynamic menu on a webpage). If you click first option inside the Form connected with the StripMenu you will get some controls that allows you to do something(like inputs on a webpage). If you click the second all these options will disappear and you will get a fresh set of controls where you can do somethingelse (simply another webpage to play with).
What is the best way to do it (I find it amazing hard to find out :) ). Only way I figured out (more from experience in js then tutorials) is to use show/hide like in javascript/html.
ExamplePanel.Visible = false;
ExampleOtherPanel.Visible = true;
But this doesn't seem right - I think it would be impossible to manage in bigger program (not only in code, but visual designer too - you can only fit that much Panels inside Form).
Any advice? Or at least a link to material where I can find out?
EDIT:
Finaly I gave up and used multiple Forms as sugested in answer.
private void MenuStripExample_Click_1(object sender, EventArgs e)
{
SomeForm SomeForm = new SomeForm();
this.Hide(); //Hide the main form before showing the secondary
SomeForm.ShowDialog(); //Show secondary form, code execution stop until SomeForm is closed
//this.Show(); //You may uncomment this if you want to have the previous Form to get back after you close new one
}
You normaly don't hide and show panels with different layouts. This is not a good design.
If you have complete different navigations/control sets, then create a new Form which is responsible for the control set.
If you don't want to use new Forms take a look at the TabControl.
You may also want to take a look at MDI-Container. You can use a Form as a MDI-Container and display various other Forms as child-elements inside of this container.
Is their something like iframe in c#?
I want to build an application with one form that its content changes according to the actions I do, like messenger live. The part when I log in and log out its too different "windows" but it happens in the same form.
There is no iframe equivalent in winforms or wpf, but there are ways to deal with it.
For either winforms or wpf, what you want to do is have a Panel which you change the content of.
A panel is a container which holds/encapsulates other controls.
If you have two different views you want to toggle between, create two panels at the same position with the content you need. Then you will show one and hide the other. When the user executes some action which requires you to change the view, then simply hide the displaying panel, and unhide/show the other one.
Think of it as layers, where you will only show one at a time.
You can also dynamically load user controls into a panel, much like an iframe, but I find it easier to have the content in the form, and hide/show as needed.
Assuming WinForms, how about using UserControls? Place as many as you want in a single/multiple forms, and interact as you do in forms. See, UserControl class.
You can load a form into a Panel or tabPage from a TabControl:
Form f = new Form();
f.TopLevel = false;
panel1.Controls.Add(f);
f.Show();
f.Dock = DockStyle.Fill;
Is there any framework or tutorial on how to create a wizard in C#. I need to provide the user a way to do a sequence of selections/user inputs. I thought Wizards would be an ideal way. I need Next/Back buttons on each page. I haven't created wizards yet. Any inputs would be very helpful.
I'm working on a brief article for CodeProject on a "poor man's wizard" that uses the standard WinForms TabControl as its "foundation" : but that won't be ready for a few weeks.
But think about the advantages using the standard WinForms TabControl gives you :
"less code" == "cheap" : it will handle all the "business" suggested by Manzoor Ahmed's comment above (swapping in and out a bunch of panels), with much less code.
"no painting" == "less work" : it can be used without any special ownerdraw or painting code (the Simmons article on CodeProject cited by Jay Riggs above has some optional custom painting for gradients, but I have not examined that code in depth to see if it can be used without any custom drawing/painting). Note, of course, that Manzoor's suggestion would also not demand custom drawing/painting.
flexibility in UI : you can show the Tabs, or hide them.
Here's two ideas on how to start using the TabControl as a "wizard" :
I : how to hide the Tabs themselves if you don't want them visible (assuming a TabControl named tabControl1 on a Form named Form1) :
a. if you want to restore visibility of the Tabs : create a Form scoped variable of type Region, and in the Form Load event put the current Region of the TabControl into that variable :
Region tabOriginalRegion;
private void Form1_Load(object sender, EventArgs e)
{
tabOriginalRegion = tabControl1.Region;
}
b. add this to the Form Load event to hide the Tabs
// hide the tabs
tabControl1.Region = new Region(tabControl1.DisplayRectangle);
II : once the tabs are hidden : then, obviously you'll put your own buttons on each tab page to control forward and back movement. if the tabs are visible, then you'll want to handle the TabControl's 'Selecting event : inside that Event handler you can use e.TabPage to get the "destination" Tab, and you can cancel navigation to that "destination" tab by setting e.Cancel = true.
Hope this is useful.
I've found the DevExpress XtraWizard control to be quite nice to work with
I've used this one from CodeProject:
Wizard Form Implementation
Search CodeProject for other wizards.
Try this
C# Winforms Wizard — CodeGuru.com
Alternatively, you can use panels too. Every time you move forward or backward, just change the panels.
I want to add a new tab page for every newly opened form.
Example:
frmReport reportform = new frmReport();
report.Show();
When I open the frmReport form, it must be opened in a new TabPage, as in Windows Internet Explorer 7-8 tabpages.
What you would like to achive here is to have "windows inside tab pages". This is not like it supposed to be! It looks like this:
Windows OS
Windows of applications (Window class)
Containers placed on Window (for example: Panel, TabControl!)
Controls placed on Windows and Containers (for example: Button, but also containers like Panel!)
So when you look on this you see that it's not ok to put Windows class into TabControl!
So what to do?
Create for example UserControl class and move all your controls from Window to this new UserControl. Next place on your Window TabControl nad on one of it's TabPages put this newly created UserControl.
In this way you'll have a good designed UI. Once again: You do not put Window on your TabPage!
In fact U can add Windows.Forms to TabPages you just need to do set
Form.TopLevel = false
and you can add it to any container be it TabPage or Panel
i used DevExpress Controls for tabPages.
Sorry, there is no direct way to do it. Better to go with Usercontrols instead of Forms and Add controls to the Tab Page.
See this link.