Developing WPF software without MVVM

后端 未结 5 985
走了就别回头了
走了就别回头了 2020-12-30 10:05

We want to start develop an intermediate desktop software. We decided to use the WPF. We don\'t want to use the MVVM pattern. Because we are not familiar with MVVM, and als

5条回答
  •  不思量自难忘°
    2020-12-30 10:36

    There is no requirement to use MVVM. One can use the visual designer to drag n' drop controls onto the design surface. Double click on a button and get an event handler in the code-behind. Let's not forget setting properties & event handlers via the PropertyGrid. All exactly as is done in Winforms.

    Without a DataContext data binding doesn't work. If you wish to use databinding, the first examples I've seen set the Window's DataContext = this; in the constructor. In this case the windows acts as its own 'ViewModel'.

    You can also use MVVM with View-First. No DI or IoC required.

    public class MyViewModel
    {
    }
    public class MyWindow
    {
        public MyWindow()
        {
            DataContext = new MyViewModel();
        }
    }
    

    Of course the next step is implementing DI/IoC using Unity.

提交回复
热议问题