Commands and MVVM principles - RelayCommands -


i'm new @ c#, wpf , mvvm pattern. sorry quite long post, trying set points of understanding (or non understanding).

after studying lot of texts on commanding mechanism provided wpf , mvvm pattern, have few problems getting mind straight on how use these things.

i understand commands provided wpf allows define multiple "calling points" command logic held in component of visual tree. when command called, call bubbles through visual tree (starting @ command target or focused element) until bumps element holding commandbinding defines command logic.

what seems nice can define public commands without specifying either logic nor calling points @ first.

i understand following mvvm pattern, viewmodel of view should handle logic whereas base wpf implemtentation of commands allows visual elements handle because call bubbles through visual tree.

i found custom implementations such josh smith's relaycommand can used in case, bind command called element of view (button example) relaycommand object in underlying viewmodel.

but then, dont see how it's command (by definition of wpf commanding pattern) anymore since we're directly specifying implementation referenced in viewmodel. method, loose benefits of being able call command anywhere without knowing logic implemented. in case, why not directly use click event handler (for example) ?

could explain me i'm wrong ? (thanks read post end !)

regards. nr

but then, dont see how it's command (by definition of wpf commanding pattern) anymore since we're directly specifying implementation referenced in viewmodel.

this still command, , implements icommand, it's no longer taking advantage of routing strategies built wpf. it's command, no longer routedcommand - in sense, you're right - it's not following original concepts of wpf's routed commanding infrastructure, it's still command.

with method, loose benefits of being able call command anywhere without knowing logic implemented. in case, why not directly use click event handler (for example) ?

you're still keeping benefits of having logic separated view. view doesn't need know how implemented, , viewmodel can implement command without knowing how view trigger it. command can still come gesture, button, etc - , changed (completely within xaml), without changing logic , code @ all.

switching event handlers breaks - if use event handlers, changing view's implementation requires updating event handlers (code behind).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -