General WPF Application - c#

Am just creating myself a WPF application, like outlook. am having all forms seperately. I just want one main window and and am haivng navigation pane in left side. when ever i click items in pane, i just want to load corresponding form to the main window in right container. How i can do this?

Use a design pattern like MVP or MVVM..
Also you probably want to use the Command pattern which will benefit the maintainability of your UI related commands.
Tutorials:
WPF Patterns
This tutorial should get you started with these patterns. Paul Stovell shows how to implement MVP and MVVM and displays strenghts and weaknesses of each pattern.
OutlookBar:
This link should get you started with the UI part of your challenge. It shows how to use such a control and implement the Command pattern.
HTH

Related

Winform control code placement

I'm adding a bar manager and popup menu control to a Winforms application. I have to add the code to bind the menu to the manager, but I don't know where it would be best to do so.
I'll be using the designer heavily (company mandated) for the rest of the build-out, but the binding has to be done in code AFAIK. Currently I have it in the form load method.
I believe this is just fine to make it work, but I'm curious if you could put it in the designer code with the control details, or if it should go somewhere else in the code behind.
Hopefully this isn't an opinion based question.
Winforms doesn't make it very easy to separate things correctly, but you should try to separate as much as possible the UI code from the functional code.
Basically, you should try to put all your business logic in classes that are separated from your UI. Try to think that all that code could be used by another type of application, like a web app, or a WPF app.
The things that are in the codebehind should be only related to UI management, updating the UI and passing the changes to your business classes. There also seems to be some things that exist to have a MVVM or MVP on Winforms, check this SO question: UI Design Pattern for Windows Forms (like MVVM for WPF).

The "pretty" way to make a modal dialog in WPF with Prism and MVVM Pattern

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.

convert mdi application to mvvm wpf application

I have a winform application that I want to convert to WPF
It has a main form (MDI) and the children can call each other as well.
I read that MDI is not a good practice according to the mvvm. But I saw that application have the look and feel that I want (e.g:Prism- I was told that it is too complicated for beginners and for a small application like I need).
Do you know a small WPF project that follow the mvvm rules and has the look and feel of MDI application?
Thanks
Asaf
MDI is a GUI design pattern. MVVM is a programming design pattern. The two really aren't related at all. You can do either one or both together.
It is true, however, that many GUI design experts frown upon MDI but that's entirely because of usability for the end-user... not because of the underlying code.
Perhaps if you describe or provide a mockup of the UI you want to create we can provide guidance on how to implement it in WPF.

MVVM like wizard

I am currently building an MVVM based application. The application should also have a wizard in MVVM style. The wizard is not a normal wizard, its a particular kind of a wizard. My goal is to implement a wizard with
1.) has also multiple branches. The wizard can guide you in other direction. So the wizard must not be straightforward.
2.) can also have short cuts. You can skip some pages where default values are setted.
3.) is also normal - straightforward.
Note, some information in the wizrad pages are on-the-fly. That means, that the information can be passed between each step and processed.
Are there any approaches like patterns to solve my problem? How do I implement it the best way?
Did you read this good article in Code Project about Wizard in MVVM and written by two MVVM guru:
http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx?display=Print
You might have a look at the ViewModel sample application of the WPF Application Framework (WAF). It shows how to implement a Wizard in a MVVM way.
If your wizard has a single VM that stores the state/results of each step and sits behind a view that is a user control...
You could have a Frame on the wizard view that requires 2 events in the code behind (This obviously depends on if your MVVM architecture can live with this?).
Event 1) When the binding of your wizards step raises its NotifyPropertyChanged: tell your frame to "Navigate" to the appropriate page (as described in a property in your wizard VM).
Event 2) On the frames "Navigated" event so that you can point the current pages data-context at your VM.
This way the wizard viewmodel controls the state of the wizard from start to finish and it also can describe the steps, which can easily be added to, edited, etc.
Obviously this may not sit well with everyone's view of MVVM.

Developing wizard UI - WPF

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

Categories