Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid tight coupling between the CommandName in the XAML and the ViewModel

Tags:

mvvm

wpf

I am having multiple views which are databind to single view model. Now i see a tight coupling with the command name in the different views with the ViewModel. So i need to avaoid this tight coupling. Any help will be highly appreciated.

Cheers, Sajesh Nambiar

like image 553
sajesh Nambiar Avatar asked Nov 05 '22 10:11

sajesh Nambiar


1 Answers

This is pretty normal practice when both View and ViewModel references the same command names, this is like a common protocol/public interface. Look at this from an other point of view, Comamnd Name is like a public interface which supported by both sides - View and ViewModel. So

  • If View able to notify an udnerlying ViewModel in a given case it refer to a command by a command name
  • If ViewModel able/want to handle any specific command - it exposes a Command via public interface and register it by a Name, providing own command handling logic as well

If we look at Commands from Events standpoint - View able to "raise" a given Command in a particular case and exposes this Event (Command) by specifying it Name (like exposing public event) and this is question of ViewModel whether it would handle such a command (subscribe to Event).

like image 192
sll Avatar answered Nov 14 '22 22:11

sll