Command in Catel 3.0

Mar 12, 2012 at 12:19 PM

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.

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?

Mar 12, 2012 at 1:31 PM

It *does* have a constructor with a tag:

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

Mar 12, 2012 at 1:37 PM

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

And with the tag its the way it should be?


Mar 12, 2012 at 1: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"))