Ok, I'm being really thick here and am having a few minor issues which are turning into major ones in my head:
I have a MainWindow that houses a tab control into which I have several "apps" sitting which all have their own solutions. I have built a neat "loading" control which is housed in the main window but is hidden and is only displayed when one of the displayed pages has a button clicked. However, I don't seem to be able to access the user control from the page.
As an example, I have an admin page which controls users in a database which wotks fine. When I click on the submit button I want to make the user control visible on the MainWindow and when the function is finished to hide the control. I know how to unhide and hide the control just not how to access it. I have attached a representation of the file structure below so you can see the issue I have accessing the MainWindow in the main solution from say the pageAdmin.xaml.
I have been googalizing this for a while and can't seem to find a solution that works. Can anyone point me in the right direction? I am open to any suggestions about how to handle this.
Andy
Just to be sure: what do you mean with "apps"? Do you have one WPF application which hosts different components?
Maybe PRISM (Microsoft Framework) is interesting for you. In PRISM you can dynamically load components from different dlls and host them in one WPF application. It has a build in messaging framwork which works very well and the diffetent dlls don't need any references among themselves.
Related
Some questions. What option is much better, create a lot of windows in project to move from one window, to another. Or, work in one window and just when I need to move from login window for example, just clear the Grid and Load another Grid with their controls, objects etc. Accept any tips, thanks
You should probably check with your users.
Flow from one window to another is wizard dialog. You can be sure that all steps are taken. But expert users that may be annoying.
On the other side showing all options in main window may be overwhelming for novice users and excellent for experts :)
I like to create just one Window, put a top menu on it, and a ContentPresenter in the center of the window. Then, I create some UserControls that are the "pages" of the app. On the top menu, handle the click events. For example, on the "User Profile" menu, open up the UserProfile page:
contentControl.Content = new UserProfile();
where UserProfile is the UserControl you created.
Also, read about MVVM. If you come from a WindowsForms/WebForms world, then it you be confusing in the beginning, but if you have time to learn, it does worth the effort.
I have a WPF application running on Windows 8. It is the one-window application that has three different views in the whole client area of the main window: live video from a webcam, help screen, and resource usage status. As you can see they are not related or interact each other, but I want to show them in one window rather than poping up a new window. The views will be switched by clicking a button in each view or by typing a keyboard shortcut.
I'm currently implementing each view using UserControl, and then adding/removing those UserControls in the grid of MainWindow on user events. I'm not sure if using the UserControl is the right direction because UserControl brings up the image of small widgets like buttons rather than a whole window content to me.
Am I doing correctly? I just looked at the Page control, but I'm not sure if it is a good idea. Thanks in advance!
I'm currently implementing each view using UserControl, and then adding/removing those UserControls in the grid of MainWindow on user events. I'm not sure if using the UserControl is the right direction because UserControl brings up the image of small widgets like buttons rather than a whole window content to me.
There is nothing wrong with a UserControl providing the bulk (or all) of the content for a Window. In fact, this is fairly common when using frameworks, as the Window is created for you in some frameworks.
I would not worry about using a UserControl for this.
Another popular way to implement multiple views on a single WPF window is to use a Tab Control and have each tab set to different user controls.
User Controls are definitely useful, and you have done something perfectly valid.
I've created a screen in compact framework using the form editor, is there a way I can grab this screen or at least some components of it and use them in multiple places in the compact framework app?
Yes, tcarvin is right, just create a user control and then reuse this in your compact framework application as often as you need.
To start right click in VS on the project name in solution explorer:
In the popup menu click Add and then UserControl. Accept or change the file name for the user control and then you are looking at the empty user control:
You can now resize the user control canvas and then place other controls as buttons, labels, textboxes etc. on it:
You can then also enter code for button events etc. In the example one can add code to use openfiledialog to select a file and the filename will then displayed in the textbox.
When you are ready, you have to build your solution to get an updated control list on the left in visual studio. Back to a window form design view, you can then place your usercontrol:
Is that simple?
You can also build a library with user controls and then reuse your controls in every compact framework project where you reference the library.
~josef
It sounds like you need to look at UserControls. They let you create add one or more controls to a surface (the UserControl), and then you can add that UserControl to as many forms in your application as you want.
All in WPF:
Developing a wizard application, user has to answer a number of simple questions before brought to the main app. The main app is then prefilled with the information obtained from the wizard.
I started with a Window which I then planned to add usercontrols to. The main window would have the user control in the first row, then Next and Previous buttons to control moving between the controls in the second row. This way I could easily control the logic to switch between screens like:
WizardControl1.IsVisible = false;
WizardControl2.IsVisible = true;
But for some reason, user controls do not have setter for IsVisible. Hurray.
So then I thought I would just use seperate windows for each section of the wizard. The problem with this approach is that now when stepping between, the window opens in random positions, and by steppign through the wizard with next, the next window pops up randomly which is really distracting and frustrating.
So how can I develop a wizard properly? I don't get why this is so hard...not exactly rocket science... replacing text and controls and storing input after pressing next/previous!
Thanks
Check this link:
http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx
This is the article about building wizard in WPF by Josh Smith, it's seems to be nice pattern.
I found it's helpful for me, hope you'll too.
There is also an open source Avalon Wizard control on codeplex.
I'd probably aproach this using data binding and template selectors. Have the wizard form bind to a "WizardData" class, which exposes a list of "WizardPage" base classes.
The WizardData class can expose properties defining the correct info on the forms, and display a control for the main page that uses a template selector to determine the proper control to display based on the actual type of the particular wizard page.
It sounds like more work than it is, really. It also gives you the benefit of good separation between code and UI (all "work" is done by the WizardData and WizardPage classes), and the ability to test logic independent of the UI.
It's also a very WPF/MVVM way of approaching the problem.
I recognize this does not directly address your question, but I thought I'd mention it as a possible alternative. I've used Actipro's Wizard control with pretty good results, and when I have needed support, they have been very responsive. I am not affiliated with them in any way; I just like not having to write the plumbing to manage a wizard.
The property is called "Visibility".
I find that I do better when I dynamically add and removing controls rather than hide them.
I was looking for a Wizard solution too. I have the need to stick with stock WPF components so I implemented the wizard using a standard form and a tab control.
I only hide the tabs at runtime so there available in the IDE. At runtime just use Back, Next, Finish... to navigate thru the tab items
works good
For instance, I have an application that has a main window and then child windows inside of it.
http://screenshots.rd.to/sn/e3hek/sapienfullwindow.png
http://screenshots.rd.to/sn/e3hek/appscreen8.png
What i need is to grab each individual child window of that application, and display them as tabs in my application, or on a panel's handle.
I already have code to kidnap the application and put it into mine, and it works great.
MDI support is already present in the C#. So the first screenshot is using the MDI option.
The second screenshot is using tabbed windows. Now you have two options:
Use this opensource library DockPanelSuite which will let you have tabs in your application. something similar to visual studio interface. You can create forms and then tab it based on your needs. You can even dock them anywhere in the parent form by drag and drop. Just like in visual studio.
The second option is to create a form with tab control covering the whole windows. There you create tabs using the resource editor and hide/show based on the forms you want to display to the end user.
In my opinion, use the first option which gives you lot more customization. Also if you use the dockpanel, you can switch between the views shown in your first screenshot and second one. So user has better control as to how he wants to view. Dockpanel is free to use even in commerical apps and comes with source code. So you can either use the dll or directly incorporate the code in your application.