Starting WPF MVVM. Use a framework? [closed]

2019-01-23 18:15发布

I took a look at some questions here at stack overflow like this & mix10 building your own mvvm framework

I wonder if as a beginner its better to start from scratch (but I heard from the vid, its not recommended) or use a framework

also which is more suited as a beginner framework to learn? I find that after reading quite a few articles or even tutorial videos I am still quite lost. I may get parts here and there but still not there.

caliburn micro a smaller framework easy to learn? or something from microsoft like MVVM toolkit or Unity/Prism (whats the diff bet all this MS frameworks btw)? MVVM Light?

4条回答
我只想做你的唯一
2楼-- · 2019-01-23 18:31

IMO, there no need to use a framework. MVVM is just a way of doing things.

For a start, you only need a RelayCommand class, so you can bind commands to your viewModel. You can download it from Josh Smith MVVM Foundation

Then when you are more advanced you can add other classes like:

  • ObservableObject: This is intended to be the base class for ViewModel types, or any type that must provide property change notifications. It implements INotifyPropertyChanged and, in debug builds, will verify that all property names passed through the PropertyChanged event are valid properties. This class used to be called ViewModelBase.

  • Messenger: The Messenger class is a lightweight way of passing messages between various ViewModel objects who do not need to be aware of each other. This is based on the Mediator implementation created by Marlon Grech and Josh Smith, as seen on Marlon's blog.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-23 18:48

My $0.02 :

I've started using WPF / the Mvvm-pattern a few weeks ago and one route I can definitely recommend is first starting a test-project, reading a lot about mvvm, and trying to implement it yourself (even if it's just by using parts of other people's stuff). Implement something, read some more, go back and change stuff, and then read some more.

Do this for the first 2 weeks and you'll get an idea of what it's actually all about, you'll see some problems and find some solutions, etcetera. Basicly this will get the mvvm-idea in your fingers and give you some hands-on experience.

Then if you like you can throw away your test-project, decide wether or not to really start writing your own stuff or using an existing kit, and probably have more appreciation and understanding for the way existing kits work.

I ended up not using an existing kit but my own very simple implementation since I didn't need much complexity for my project, but I did get a lot more appreciation for some implementations I've seen discussed on the interwebs.

Edit: When I talk about "two weeks" I mean "two weeks of sparetime" which is about 25 real hours ;-)

查看更多
一夜七次
4楼-- · 2019-01-23 18:57

From my point of view, If you are learning WPF/MVVM for yourself then you must learn MVVM thoroughly and try to build a framework from scratch(As explained by Eduardo)

But if you are starting with a Commercial project or Enterprise application then you must consider using some established framework like PRISM or Caliburn or MVVM Light Toolkit.

We had not used any framework in my first project and I somewhat regret that. Although nothing went wrong and it was not very tough to build your own framework(as Eduardo said) but it took us a lot of time and a no. of iterations in finalizing various base classes etc. Also, we couldn't take the advantage of various things which are already implemented in some of these frameworks(as we didn't knew about them at all).

查看更多
成全新的幸福
5楼-- · 2019-01-23 18:57

I think it will be better to start with a hello world application. Slowly get acustomed with the controls (listview, gridivew...) and then basic wpf concepts (binding, templates, triggers...). After that you can move on to MVVM.

查看更多
登录 后发表回答