Can someone explain me, why command pattern is using with WPF MVVM, why not other pattern.
Loading
Can someone explain me, why command pattern is using with WPF MVVM, why not other pattern.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Jul 10, 2021, 3:12 PM
First, what is a design pattern?
A design pattern is well tested and accepted technique to solve a software problem that occurs multiple times. for example, in web development, if a class creates an object of another class then both classes become tightly coupled, to solve this issue we can either follow a factory pattern where the factory class will be responsible to generate the concrete object or the DI pattern where dependencies can be injected through constructor, property or method at run time.
Now, move to cmd pattern, The command pattern is a good way to encapsulate user interaction code. Its main strength is that it allows you to keep your view--code-behind clean-- and flexible. You can swap out commands as needed, and set up the same command to multiple control events.
That is why it is widely accepted among the WPF community.
Sonil KumarPosted Jul 31, 2021, 5:35 PM
It is not true that command pattern is not used used with other architecture. It is a pattern and can be used anywhere.
For your question, WPF and MVVM supports command with binding, and you can call your command with bind in XAML. So it is easy and clean code to use. That is why you have seems this pattern with WPF most of time.