Parts required for use in the MVVM Framework

As my company migrates to the .NET platform from VB6, it looks like we're moving towards WPF (my boss is in love with Office-style ribbon management). I worked on mocking one of our VB6 applications in WPF and decided to experiment with MVVM at the same time. I don’t like using the existing MVVM framework, so I think I need to write my own. The biggest problem now seems to be the method of registering and managing all my views from a central place - the manager class, but I'm not quite sure how to implement this. I see an article about IoC and ServiceLocator, but I have time to use these ideas.

Does anyone have any suggestions for features and templates that I have to implement in order to make a very light but workable MVVM environment? Besides the existing structure, what existing code resources would you use to help promote this project?

+3
source share
4 answers

, MVVM Framework Rob Eisenberg Caliburn. , MVVM Framework. IMHO Caliburn 100+" MVVMish ". . Calibrun Micro, , .

, MVVM. WPF , , MVC, MVP. Infact Caliburn . , , MVVM.

+4

MVVM, .

public interface IView<C>
    where C : class
{
}

public interface IView<C, VM> : IView<C>
    where C : class
    where VM : IViewModel
{
    IDisposable Bind(VM viewModel);
}

public interface IViewModel : INotifyPropertyChanged
{
}

public interface IViewModel<M> : IViewModel
    where M : class
{
    IView<C> Bind<C>(M model) where C : class;
    IView<C> Bind<C>(string key, M model) where C : class;
}

public interface IViewModel<VM, M> : IViewModel<M>
    where VM : IViewModel<VM, M>
    where M : class
{
}

Person .

public interface IPerson : INotifyPropertyChanged
{
    string Name { get; set; }
    DateTime? Dob { get; set; }
}

public interface IPersonViewModel : IViewModel<IPersonViewModel, IPerson>
{
    string Name { get; set; }
    DateTime? Dob { get; set; }
    int? Age { get; }
    string Title { get; }
}

, , :

[Factory(typeof(IView<Control, IPersonViewModel>))]
public partial class PersonView : UserControl, IView<Control, IPersonViewModel>
{
    public PersonView()
    {
        InitializeComponent();
    }

    public IDisposable Bind(IPersonViewModel viewModel)
    {
        this.personViewModelBindingSource.DataSource = viewModel;
        return Disposable.Create(() => this.personViewModelBindingSource.Dispose());
    }
}

, , :

var personM = context.Resolve<IPerson>();
var personVM = context.Resolve<IPersonViewModel>();
var personV = personVM.Bind<Control>(personM);

var personC = personV.AsControl();
personC.Dock = DockStyle.Fill;
this.panel1.Controls.Add(personC);

, . Bind . , Windows Forms, WPF Silverlight.

, , .

0

, , MVVM, .

, , , .

Magellan Framework. .

0

, MVVM-.

I think it is a less good idea to do this without exploring the other MVVM frameworks there, exploring what tools they include, and understanding their design. This is not a lot of work to create the least useful MVVM toolkit, but a lot of work to figure out what tools you need to build.

In addition, if you look at how other developers have resolved some of the problems you are facing, you may find that you do not understand the problem yet.

0
source

Source: https://habr.com/ru/post/1765271/


All Articles