How to organize architecture WPF project? - c#

In my WPF project i want to have only one Window - MainWindow and UserControls as working part. I have some little different applications in one, and want to make navigation on top of my MainWindow as buttons. And little applications as UserControl. In MainWindow - grid with Big Empty Zone - which use to keep and run work. But, i want to navigate to other userControl from another. (probably do not understand :()
How organize architecture WPF project that: one main window and many usercontrols which places in mainwindow and replace each other in turn. and there is the possibility of navigating from another usercontrol to another.
May be it's MVVM, but i don't understand how this pattern can help me.

You might be interested in the ViewModel sample application of the WPF Application Framework (WAF) project.

My best source is here. Its the place that got me started on my journey to MVVM. Full working examples and workable solutions.

http://compositewpf.codeplex.com/Wikipage - I was looking for it in past and it's the only thing I've found so far.
How to design parts of the application in XAML and how to reusing it then?

Related

More views of a form in c#

Let's say I have two "views". Each view has it's own button, which makes other view to appear. All should be managed in one window. So how do I achieve this? Im looking for something like viewController in iOS...
I tried to use one filled, docked panel - but than all classes are active, so it doesn't seem like a good solution. I also tried user classes (like this), it works, but it's complicated and I have big deal sending data between these classes.
There is no such thing as "views" of a form. The concept of what a UIViewController can do in iOS is different than building a properly functioning form in C#. You need to learn some new skills now and approach this from a different perspective.
The basic principle is to build a form with controls (either manually or through code or both), change the properties of those controls manually or through code and use the methods they support. You can do what you want, but it's going to take learning some new things.
Try checking this out:
https://msdn.microsoft.com/en-us/library/360kwx3z(v=vs.90).aspx
It's not 100% clear what you are trying to do, but it sounds like you should look into User Controls or Composite Controls.

Create Single Window Navigation in WPF

I want to create a kiosk mode application using WPF. I want to use a single window because the user should not be able to exit this fullscreen application.
The application should guide the user trough a process. When the user proceeds trough the process, the screen should constantly change and show him the next step.
Usually I just create a single window and use a "state machine" to switch UserControls containing the information for the current step. Is there a better way to achieve this functionality? Maybe I would get a better result using multiple windows or Pages (never used them).
The reason why I am asking is that in future I want to have a simple, clean way of switching the content inside a single window. i.e. I am planning to implement some sort of animation when switching content (like sliding to the next / previous step). I don't want to put more effort into my current approach if it isn't the most flexible and clean one.
Any ideas?
PS: This is about desktop applications. Today I come from the Winforms environment and am experimenting with WPF.
There's a few ways you can achieve this.
First would be to use a Page based application, this will allow you to use a single window. Here is a pretty interesting tutorial
A bonus of using this approach is that navigation between pages is built in.
Your requirements are that you need to use animation for transitioning between pages, as far as I'm aware, using a Page based application cannot achieve this (I may be wrong). So your other option would be to use a UserControl MVVM approach.
This probably won't make a lot of sense now, but here goes:
You can use a single master view model which will hold multiple child view models, each of these could have a visibility property which dictates the visibility of the associated view. The master view model would simply be responsible for displaying the appropriate view model depending on where the user currently is in the application.
Using some clever XAML, you can create storyboards (animations) when the view becomes visible, which will allow you to achieve the crazy awesome animations that you require.
Anyway, that probably didn't make any sense, so here's a tutorial to get you started with MVVM.

Bubbling Events from UserControl using MVVM in WPF..?

First of all, I want to let everyone know that I'm very new to the MVVM concept, and have looked pretty extensively for some explanation of what I want to do, but to no avail.
In the program I'm working on, I have a UserControl with a few buttons on it, which need to control the navigation of the main window. I have 3 different "pages" I want to be able to switch between in my main window. Instead of pages, I decided (for whatever reason, correct me if this is not the best approach) to use a UserControl for each page, and switch the visibility to the correct one. I need the data to persist while switching, so I don't believe that creating new instances of the Usercontrols will work.
My question is: How can I bubble the events from my "NavBarView" to the main window in a way that will allow me to switch the visibility, but in a MVVM way? I know I may be completely going about this the wrong way, and I'm happy to take any suggestions on a better way of achieving this navigation.
I have to use WPF, so WinForms is not an option. Too much transparency and custom controls for WinForms.
I would make the "NavBar" part of the main window if possible and use that to control the sub controls in the forms. I would be careful nesting User Controls. If you can avoid it I would (key indication is are you going to reuse it somewhere else). I took over a project a while back that had a main window with 3 separate highly coupled user controls that had to all work together and it was a nightmare. The only way I could get it to work somewhat safely was to have them all set their data context to the same view model. If I had to do it from scratch - would have taken a completely different approach with a single view.

how to separate separate function(tab) in wpf c#?

I have got my Mainwindow class , Mainwindow.xaml and Mainwindow.cs. Problem is I have got 4 tabs and each tab has own functions. All this is on my Mainwindow.xaml and cs. Is there any way of separating them because my Mainwindow.Xaml is getting bigger and bigger and then I get confuse with so much code.Probably is bit basic what I am asking but I dont know how to do separate with xaml, becasue I want to keep the layout as it is.
Hope I have explained well.
Thanks in advance
You can use different UserControls for each tab. And each tab has the corresponding UserControl like this:
<myControls:userProfileTabControl />
Here is some more documentation on how to create and use a UserControl in WPF. There is also a video over att WindowsClient that talks about "How to Create a User Control in WPF".
When you feel comfortable with the basis of WPF you might want to consider looking into the MVVM pattern, you can read about it over at MSDN, there are frameworks to use to make MVVM easier such as PRISM. But often they tend to do things a bit more complicated.
Start off by seperating your tabs into different User Controls and go from there.
If it's a small application, you can create a User control for each tab's content, and then implement all the logic there. You then embed your user controls in each tab.
If the application can grow, or you want to put a bit more of order in there, take a look to The PRISM Framework

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