Command in Catel 3.0

Mar 12, 2012 at 11:19 AM

For the InterestedInAttribute it was necessary for me to give a Command a Tag.

SelectComponent = new Command(OnSelectComponentExecute,"SelectComponent"); 

So in an other Viemodle im Interested in this Command.

 [InterestedIn(typeof(WatchedViewModel))]
public class TheOtherViewModel : ViewModelBase
{
   ...

   protected override void OnViewModelCommandExecuted(IViewModel viewModel, ICatelCommand command, object commandParameter)
   {
      if ((string)command.Tag == "SelectComponent")
      {
          ...
      }
    }
}

In Catel 3.0 there is no Constructor with secondparameter "Tag".

 

Is there a better solution?

Coordinator
Mar 12, 2012 at 12:31 PM

It *does* have a constructor with a tag:

SelectComponent = new Command(OnSelectComponentExecute, null, "SelectComponent");

Mar 12, 2012 at 12:37 PM

Oh. Ok. Why i don't see it. Strange :-)

And with the tag its the way it should be?

 

Coordinator
Mar 12, 2012 at 12:50 PM

Yep, the only thing I recommend is to use the TagHelper class isntead of comparing strings. Sometimes, the .NET does not compare strings as strings but as reference, and then equal strings will not be treated as equal strings. The TagHelper in Catel solves this issue:

if (TagHelper.AreTagsEqual(command.Tag, "SelectComponent"))