سؤال

In MVVM, Model will usually have the data model, view is UI (XAML) which is further binded to the properties VM, ViewModel which typically inherits INotifyPropertyChanged.

When it comes to event handling, are there any specific pattern to handle all events on UI? For Ex: Lets say if we have save/new/close button or some other button... and desired goal is when user does some operation and clicks on any of the button, control should go to code behind and should perform desired operation... how should I make sure that I have done the event handling in proper manner? and which interface I should use / when and how?

like we have ICommand interface/Relay command/Delegate command... I am not clear with this..

Thanks in advance for your response to my query...

هل كانت مفيدة؟

المحلول

Amit, if you are planning to hook up buttons, the accepted way is to use an implementation of ICommand (my personal preference is RoutedCommand). If you are aiming of to raise and handle events, have a look at Event Aggregators which is based on Publisher/Subscriber pattern.

In this, you will register a method (message handler) to ‘listen’ to a message (event) that matches a pattern. Once you done that, you can raise/publish messages (events) and when a match is found, the correct handler will gat raised

PRISM framework by Microsoft has done a good job of implementing event aggregate pattern

http://msdn.microsoft.com/en-us/library/ff921122(v=pandp.20).aspx

Hope this is useful

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top