How do you use a presentation model with Winforms?

I would like to know how best to implement the presentation model template. I read about MVVM, but not applicable to me since I am not using Silverlight or WPF.

+3
source share
2 answers

Upgrade controls implements a presentation model template in Windows Forms. You are writing a model class using independent fields.

public class Person
{
    private Independent<string> _first = new Independent<string>();
    private Independent<string> _last = new Independent<string>();

    public string First
    {
        get { return _first; }
        set { _first.Value = value; }
    }

    public string Last
    {
        get { return _last; }
        set { _last.Value = value; }
    }
}

Then you write a presentation model with regular properties.

public class PersonPresentationModel
{
    private Person _person;

    public PersonPresentationModel(Person person)
    {
        _person = person;
    }

    public Person Person
    {
        get { return _person; }
    }

    public string FullName
    {
        get { return _person.Last + ", " + _person.First; }
    }
}

Event management in Windows Forms controls to retrieve data from a presentation model.

    private string FirstName_GetText()
    {
        return _presentationModel.Person.First;
    }

    private void FirstName_SetText(string value)
    {
        _presentationModel.Person.First = value;
    }

    private string LastName_GetText()
    {
        return _presentationModel.Person.Last;
    }

    private void LastName_SetText(string value)
    {
        _presentationModel.Person.Last = value;
    }

    private string FullName_GetText()
    {
        return _presentationModel.FullName;
    }

Windows Forms . , , .

0

MVP (Model View Presenter) , , CAB ( MS Pattern and Practice)

MVP, winform.

. .

0

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


All Articles