Developing WPF software without MVVM

后端 未结 5 958
走了就别回头了
走了就别回头了 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.

    0 讨论(0)
  • 2020-12-30 10:42

    You can develop any application by WinForm and WPF without any Design Pattern or Application Pattern.

    0 讨论(0)
  • 2020-12-30 10:48

    You don't need to rely on MVVM when using wpf. Really the keys to using wpf properly are:

    • use commands instead of events (you might do this without realizing it, but check to make sure)
    • Use data binding instead of getting values off of controls directly
    • Set the data context and bind to that instead of binding to the code behind

    MVVM works really well for these two things but is not required. Specifically, MVVM requires a 3-tier strict separation of concerns that can just as easily be done with MVP.

    As far as performance is concerned, that really depends on the platform on which the app is run and the coding style. If you run it on a computer without a decent graphics card then winForms will probably perform better because wpf will probably revert to software rendering which will be very slow. If you need to do 3d graphics then wpf is really your only option.

    Someone else's recommendation to NOT use MVVM.

    A codeproject example of how to do MVP with wpf

    0 讨论(0)
  • 2020-12-30 10:49

    MVVM is not required but it solves some common problems with presentation logic. For example, consider the IsBusy ViewModel property. It is set from any operation that has a duration and can be used from Command.CanExecute to signal bound controls to disable themselves when something is running. One property for both logic and UI manipulation. You can think more examples like this that will guide you towards MVVM. It's what the bindings offer that matters, not the pattern it self.

    0 讨论(0)
  • 2020-12-30 11:01

    You surely do not have to rely on MVVM when using WPF/Silverlight.

    As for the performance difference - it could depend on the style of your coding, however if done properly, the difference should not be noticeable.

    0 讨论(0)
提交回复
热议问题