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.
Related
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.
yesterday i used google to find a few ways to make an awesome reusable modal dialog in WPF with PRISM 4.1 and the MVVM pattern. I found some examples but i must say non of those were as "pretty" as i liked them to be.
This one: WPF Modal Dialog (no mvvm -> no use)
This is pretty nice: Showing Dialogs when using the MVVM Pattern (but still it's using a selfmade ServiceLocator which i don't need as i am using the IUnity Container. I could use the logic and rewrite it to Unity but that's not the "pretty" way in my honest opinion.
Well after a while searching the web for informations some blog (can't find the source right now) told me that the PRISM Framework got something called "interaction requests". So i checked out the prism documentation and found a small part under the topic "advanced mvvm scenarios" but the information given in the documentation aren't enough.
I'd like to know if somebody have any good example or any good blogpost about how to realize an awesome modal dialog in prism wpf with mvvm.
EDIT:
Regarding the question in the comments:
What makes a modal dialog awesome?
Indeed a good question.
It must be modal (while the dialog is open the rest of the UI
should be freezed)
The dialog view can have it's own viewmodel or
at least i would like to give an instance of an object to the dialog
view and return an object back to the parent view
The view should be an own "xaml" file
the dialogresult feature from .NET or at
least a way to get a response what the user clicked in the dialog
PRISM 5.0 came up with quick solution to show modal dialogs. Using PopupWindowAction.
<prism:InteractionRequestTrigger SourceObject="{Binding CustomPopupViewRequest, Mode=OneWay}">
<prism:PopupWindowAction>
<prism:PopupWindowAction.WindowContent>
<views:CustomPopupView />
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
Interaction requests require a little more up-front work, but they are definitely the right way to go from the MVVM purist perspective...
I saw an example of how to do this with Prism in Karl Shifflett's MVVM In The Box training extension.
As I remember, the example was pretty rough around the edges, but it should set you in the right direction.
The problem with this kind of in-view "Dialog" is it doesn't allow the dialog to go outside the bounds of the parent window. On the plus side, you can do a lot of fancy layout and animation stuff.
check my post from here
its simple, its mvvm, its a service and "all you have to do" in your viewmodel is:
var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", dialogwindowVM);
Caveat: I have not used PRISM and my answer assumes the use of just WPF and MVVM. I don't see this as a major problem as your list of requirements can be met without PRISM (which can be added on top of the basic solution at a later date anyway).
I have a project on Github which provides a custom FrameworkElement called ModalContentPresenter that allows modal content to be displayed. The element basically consists of two panes, one layered on top of the other. The back pane hosts your main content and the front pane hosts your modal content. The element has a dependency property which controls if the modal content is shown.
The element only provides the basic 'modal' functionality and is capable of hosting arbitrary content (like most WPF controls). If, for example, the modal content you are displaying is to look and behave like a window (have a title, close button, mouse drag etc.) then you will still need to do some work.
Here is how the ModalContentPresenter can address your requirements:
It must be modal (while the dialog is open the rest of the UI should be freezed)
The ModalcontentPresenter can be placed at any level within your visual hierarchy and anything behind the modal content (when displayed) will be inaccessible. The controls will still be enabled and will still react to any changes in the viewModel they are bound to but the user will be unable to navigate and interact with the controls using the mouse and keyboard.
The dialog view can have it's own viewmodel or at least I would like to give an instance of an object to the dialog view and return an object back to the parent view.
This Stackoverflow answer shows how I would recommend you achieve this.
The view should be an own "xaml" file
Both the primary and modal content can be defined using inline xaml or separate xaml files (such as a UserControl).
the dialogresult feature from .NET or at least a way to get a response what the user clicked in the dialog
The linked answer above shows how to get an 'answer' from your modal content. The basic premise is that your viewModels communicate normally (either directly or via other means such as an event bus). The only difference is that you just happen to be displaying your content in a way which means the user can only interact with the 'modal' data.
hi I want to make a wpf c# application which shows every form(Ex:- user registration, reports , etc..)in one window in other words I want to make an application which have one window and every user control appears and closed there when I want just like games in some games like middle of honor warfighter they have one window and if we chose option option buttons appear in the same window and if we chose graphics that graphic page content appear in that same window.
and I want to know is there any frame work or special method is there which I should fallow other than putting wpf controls one over another and changing there visibility and isopen status.If there is any examples please give me a link
You can use ContentControl for holding any element. also PRISM is best approach.
You can use WPF Popup forms below are some links for more info:-
http://www.dzone.com/articles/understanding-wpf-popups
http://www.c-sharpcorner.com/Blogs/11700/
Take a look at this MDI Control. It helps you to show any kind of usercontrol in one container as window.
I'm developing a bunch of user controls which do different things - like a maintenance screen, enquiry screen, report screen that sort of thing. Each screen has a dedicated purpose and a single user control holds all the functionality for the one screen.
I'm using avalondock and can place these user controls into LayoutDocuments. This creates a separate tab for each screen/user control. I've got a menu system setup so users can choose which screens they need access to. For each new screen I create a new LayoutDocument, add the appropriate control to it, then add the LayoutDocument to the Docking panel's children.
This is all working fine.
Avalon dock also has the feature of being able to drag out the layout document and make it float - you can also dock it somewhere else in the app if you wish.
I'd like to take this concept one step further: Being able to say right click on a layout document and choose "Make external window" (i'll work out the exact wording later). The effect of this action would be to create a new application with it's own icon in the task bar; being able to alt-tab between it and other apps;
Kind of like when you're in say Excel editing a document and you then open up a second instance of excel. In Windows 7 you get two excel icons in the task bar (one behind the other), and you can alt-tab between them.
This is nearly the behaviour that i'm after. However the second app isn't a full blown copy of the first; it has only the one user control that the user selected.
This is where i'm stuck and would like a bit of guidance.
I'm thinking that i'll probably need some kind of shell app where I can pass in the user control that I want. The shell would act as a window with title, X, minimising etc; the user control would then be the sole content of that shell. Use process.start to create new process and launch ?
Ideally i'd be able to pass in the same control in the same state as the user is currently viewing - so if for example they are part way through editing some customer record in a maintenance screen, then choose the "external window" option, that same customer record would appear in the new window.
Has anyone done something similar or offer advice if i'm on the right track ?
I think I know how to create a shell app but not sure on passing a user control to it dynamically. I'd like to avoid creating different shell apps for each user control.
No need to start a new process for that scenario.
Just create a new Window add your UserControl at runtime and remove the UserControl from the DockingManager. Make sure the Window has ShowInTaskbar set if you want it to show up there.
To get the command to undock the UserControl as a seperate Window you just have to restyle the ContextMenu to incorporate your command (take a look at the VS2010 theme and how the ContextMenu is styled there VS2010 theme.xaml).
I have a WPF application that loads a realtime live chart in a window,
But I end up having 10+ windows open on my desktop (as many windows as there are charts).
So my need is basically to group/embed all these WPF windows in a single window.
I tried WPF MDI but I had serious trouble since it requires the windows to be usercontrols instead, and in that case, my live chart displays but stays empty and does not refresh nor plots realtime data. Same behavior when I put my chart controls inside a Page instead of a Window (chart does not update). This is why I guess I really need to stick with windows at this point.
I welcome any simple & straight solution
Are you sure you want to have a last century MDI in your WPF application? I'd recommend to switch to other, less expensive and more flexible content arrangement. I'd organize the charts in some kind of scrollable or swipeable container, maybe with some kind of navigation or tabbing facility... If your users really want to have one or some charts in a separate window(s), let them drag the charts out of the main container and create separate window on demand (something like dragging a tab out of Interent Explorer).