开发者

WPF Magellan ViewModel IOC

I am trying to add a viewmodel to IoC but not much documentation is given on that subject by the project developers. I have added the following code to the app.xaml:

viewModelFactory.Register("ProfileCreateViewModel", () => new ProfileCreateView(), () => new ProfileCreateViewModel());
viewModelFactory.Register("ProfileEditViewModel", () => new ProfileEditView(), () => new ProfileEditViewModel(new Profile()));
viewModelFactory.Register("ProfileDeleteViewModel", () => new ProfileDeleteView(), () => new ProfileDeleteViewModel(new Profile()));

How do I resolve these viewmodels in controllers?

Please provide guidance, or any links or arti开发者_StackOverflowcles.

Thank you in advance.


I've found some information about mvvm and IoC in this question: MVVM: Tutorial from start to finish?
There is a link to a great video tutorial covering important things, that can help you greatfully when developing a WPF application. Here is the link: http://www.codeplex.com/CompositeWPF/Release/ProjectReleases.aspx?ReleaseId=19170 (direct download)
This presentation covers the basics of IoC (Unity), MVVM and data binding. Hope that will be helpful.
If you want more concrete answer then if you are using Unity, you can just apply a Dependency attribute to a property and Unity will automaticly perform the injection.

private ProfileCreateViewModel  _model;

[Dependency]
public ProfileCreateViewModel Model {
        set
        {
            _model = value;
            this.DataContext = _model;
        }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜