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.
Related
I currently have a viewmodel such that it has a grid full of appointments. I would like to double click and open up my CalendarView with the editappointmentdialog opened for the record that was selected. May I ask how would I do that in an MVVM style?
I searched the internet and found this RadScheduleViewCommands.EditAppointment.Execute(appointment, this.scheduleView); but I don't have access to the scheduleView object from the MVVM. May I ask how abouts I should do this?
I think I can achieve this if I relay it back to the view, but I'm trying to look for another approach.
The issue you have is that you can't open a view from a view model as it'll break the MVVM design pattern.
There are a couple of ways you can open a view from the view model without too much hassle:
Implement a Messenger service to publish an event to the view, like MVVMLight does.
Straight up add a Click event handler on your button and open the view in the code behind (It's still view code after all).
However my preferred method is to use an ICommand, or RelayCommand. I have written a repository on GitHub which demonstrates how to achieve this.
I recently inherited a Xamarin project where I am to work on the iOS project. Going over several tutorial I figured I was ready, however the person before me did not use storyboards or controllers! They did all customization of views in files named LoginScreens.cs (basically controller files from the looks of it).
For learning purposes and ease of transition I would like to get a storyboard going in this project. So I created a storyboard titled Main and added a ViewController and essential copy and pasted the view customization code used in the LoginScreen.cs into my controller.
To be a little more specific, I have a Main.Storyboard that looks like this:
Where I am using editText boxes and a button to act as place holders for what I actually do to them in the ViewController.cs.
This all seems to register and builds properly however when I run the debugger on iPhone 6s iOS 9.3 I get the following:
The changes appear to show, but all my storyboard iOS designer views remain in place. I am trying to see if there is a way to reflect the changes made in the controller on the storyboard.
TL;DR: I'm trying to alter some views in a programmatic way in my ViewController.cs file. These views were originally added via the iOS designer and for customization purposes, they were edited in the controller. I want to see the visual alteration I make on a view in the controller, reflect in the iOS designer and when I debug.
Sounds like you are trying to go from a project where views were all done programmatically to implementing storyboards. This is a Big change and will take some time to convert the views over.
In the cs file there will be things like Add(passwordTextFeild) which are going to add more views to your storyboard view, hence why you get alot of views in your login view. You wont be able to see these in the storyboard as they are done at runtime.
If you are looking for IBDesignable this is more for custom controls and you still will have to add code to be able to see the changes from the .cs file in the storyboard.
Check my Question for IBInspectable/IBDesignable in Xamarin
Check this official link: https://developer.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_walkthrough/
Probably not what you wanted to hear but the UI in iOS projects tend to be done in one of the three methods:
All programmatically
Storyboards
Xibs
There are tons of questions/blog posts (even a video), weighting up the pros and cons of each. So possibly the last developer felt it was best to do it programmatically
There is a setting, IBDesignable, that you can add to the declaration of UI classes in Swift or Objective-C. That tells Xcode the those UI objects have a custom interface that you want to be presented in Interface Builder.
I have no idea how (or even if you could) you would use IBDesignable in Xamarin/C#. If its not supported for Xamarin then you're probably out of luck.
I suggest you search on "Xamarin IBDesignable" on the net.
I have an application which use plugins. Each plugin is developped following MVVM, so I have a View, binded to a View-Model inside. like the following picture:
In my application I have a Designer, when I add any ViewModel in my ViewModels list, its view will appear in the Designer.
My question is: How can I keep this binding when adding the viewModel of my plugin in my list ?? how to make its view appear in my designer ?
This is an interesting question... and like always there are many ways to accomplish it.
It depends what your plugins are.
If the plugin is more integrated and not so isolated. You should think about some Factory classes which are for example named like ViewResolver or ViewModelResolver. They can take parameters like the name as string, a type, a type of an interface or work by conventions.
Purpose is to find the VM for a view and vice versa as a central service. This service should also locate plugin VM or import them for example with MEF.
For more info’s google on view-first, viewmodel-first, view viewmodel marriage, etc.
Or
If your plugins are fully fleshed out components which run independently. I would suggest your host application should have in its viewmodel a list of components which are the plugins. So the Model will be a Component no matter if it contains the view and everything else because of the hosting app is to manage the components. So you would have an ObservableCollection which are bound to content control. The content control can then host the plugin as a whole.
These are two possible ways... like I mentioned above there is no "the" way in mvvm and it always depends on your use cases...
But I hope this guides you in the right direction...
HTH
Thank you for the answer #Silverfighter! it made me things more clear !
I found a very intersting article wich seems adapted to my problem
The solution is here:
http://www.alphablog.org/2012/05/07/simple-plugin-system-based-on-ninject-and-mvvm-light-2/
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
I have some ListBoxes in my WPF app. I would like to be able to view how the design looks with out having to run the app.
But I still want to be able to bind to ItemsSource to my View Model.
I know I saw a blog post on how to do this, but I cannot seem to find it now.
To reiterate, I want dummy data at design time, but real data at run time and not break the MVVM pattern.
Any ideas?
You can check whether your code is in design mode or not. Here's a great post about doing this in different situation.
Detecting design time mode in WPF and Silverlight
Have you tried the sample data option in Blend 3? With a control open, look at the DATA tool window. There's a way to create sample data... think it does exactly what you're looking for:
http://silverzine.com/tutorials/how-to-create-sample-data-in-blend-3/