Reputation: 559
My WPF application is quite simple. I have only one view, the MainWindow which consists of a Grid with 1 column and 3 rows (TopBar, center and BottomBar). The TopBar contains some buttons and logos, the center shows two different contents depending on the application state and the BottomBar is only visible in one of those two states. One button in the TopBar changes the colors/logos of the components, like a day/night shift.
So my question is if I should write all components in the MainWindow.xaml file and show/hide the used components and also change the logos according to the day/night mode (actually just change the source property) from the source code or if I should use the MVVM pattern, which I never used before?
The problem I am facing is, that I don't have a starting point to determine which one is the better approach due to my limited knowledge.
Upvotes: 0
Views: 1029
Reputation: 1258
As pointed out in the comments this is a more opinion based question. I will answer to the best of my ability. MVVM is a design pattern that allows you to separate your project out into Models, Views, and View Models.
Why MVVM
What makes MVVM really great in WPF is that it facilitates binding your view to a view model and notifying it of any changes. As soon as you need to bind a property on your view to some external data, MVVM is a great solution.
Should you use it?
Now the other side of this is MVVM does come with a lot of overhead and can be overkill for such a small project. Due to the fact you are just learning it would be beneficial to start learning MVVM on a smaller project. If you plan on having this application grow or even create more WPF applications in the future, I would strongly recommend taking the time to learn it.
Benefits of MVVM
From personal experience once I began using MVVM everything just seemed to make sense and flow better overall. Even on smaller projects things just made more sense that way.
If you do decide to work with MVVM, I would recommend experimenting with a MVVM framework like MVVMLight (Great for beginners) or Caliburn Micro. (Again all opinion based)
Upvotes: 1
Reputation: 133
Design pattern is not the exact solution. It is guide line for making your project efficiently.
There are a lot of tries to separate the logic part and design(view) part and these challenges produce the special patterns such as MVC, MPV and MVVM. The MVVM pattern uses binding system in WPF so first you need to think about what component need binding, what your designer and core logic designer's role is and how you drive this project.
If your components just change your view area, coding in behind is better than using MVVM pattern because there is not the automatic creation system(kind of view-model) in pure IDE so you should make view-model, properties, ICommand and designate binding points in your components manually. However if view changes and interacts core logic which works a lot then you consider using MVVM pattern. So it is very important to place the pattern skills in right place.
This link is very useful and easy to understand how MVVM pattern operates and you would have insight of design your project. And there is a lot of git-hub tutorials like this link.
I don't know exact your goal but I hope my advice will help you.
Upvotes: 0