Application-wide commands using MVVM

Topics: Feature requests, Questions
May 23, 2014 at 9:20 AM

Is it possible to add commandParameter to Application-wide commands.

I tried following:

I create a command in CommandManger
var commandManager = DependencyResolver.Resolve<ICommandManager>();
in my viewmodel I Register the command
public class MyViewModel : ViewModelBase
    public MyViewModel(ICommandManager commandManager)
        SelectStationCommand = new Command<LocationInstance>(SelectStation);
        commandManager.RegisterCommand("SelectStationCommand", SelectStationCommand, this);

    public ICatelCommand SelectStationCommand { get; private set; }

      private void SelectStation(LocationInstance location)
<Button Command="{catel:CommandManagerBinding SelectStationCommand}"
            CommandParameter="{Binding LocationInstance}"
            Content="Select Station" />
But location in SelectStation is always null.

is there no ICatelCommand with parameter?
May 23, 2014 at 9:28 AM
Hello again.

Found someting: Use the generic implementation instead of ICatelCommand.
public Command<LocationInstance> SelectStationCommand { get; private set; }

but the problem still exists: location in SelectStation is null. :-(
May 23, 2014 at 10:03 PM
Note that the actual command that will be bound is the command created in the CommandManager. Currently we do not support passing command line parameters.
May 24, 2014 at 12:41 AM
May 26, 2014 at 8:23 AM
Oh great.

I downloaded the newest beta, the command is not called any more. Do I have to change anything in my Code?
May 26, 2014 at 8:24 AM
Shouldn't be. I will double check.
May 26, 2014 at 8:51 AM
Oh. I found a other problem.

I use the catel tabcontrol with the property LoadTabItems set to AllOnStartUp.
The command is created in a viewmodel of a tab. Until now the tabs are all loaded on startup. But with the newest update the tabs are only loaded after I activate them.
So the application wide command is not created on startup.
May 26, 2014 at 8:52 AM
I haven't changed anything on that. Can you debug and let me know where the error is in the Catel source?
May 26, 2014 at 9:00 AM
Application-wide commands here work as they should.
May 26, 2014 at 9:03 AM

Yes Application-wide commands works the only problem is the Tabcontrol.
I try to debug the tabcontrol. But before I have to solve my problem with the serialization exception :-(
May 26, 2014 at 9:09 AM
I am sorry, I am too busy to look into that. It would be great if you could contribute to the project by checking out the serialization changes and provide a source of the problem or even a fix.
May 26, 2014 at 9:35 AM
Difficult. Since I updated to the newest catel I have lots of problems.
  • Serialization Exception
  • TabControl not loaded correct
  • PleaseWaitService don't shows any more the given messages
  • Lots of other functionalitys in my project doesn't works any more. Maybe thats effects of the problems called before. I don't know.
May 26, 2014 at 10:46 AM
First try:

I downloaded the catel project from github: I can not open project: Catel.Extension.Controls.Shared.
-> Incompatible: This project is incompatible with the current edition of Visual Studio.

I' am using visual Studio 2013 Pro. Windows 7 without Silverlight installed. Whats wrong?
May 26, 2014 at 11:02 AM
You will need VS2013 update 2.
May 26, 2014 at 11:15 AM
Next try:

I changed back to my Tabcontrol: (Remember the tabcontrol in catel from). Now it works.
Also I get no more SerializationException.

No my problem is how to open the Project "Catel.Extension.Controls.Shared" to debug the catel:Tabcontrol.
May 26, 2014 at 11:16 AM
"No my problem is how to open the Project "Catel.Extension.Controls.Shared" to debug the catel:Tabcontrol."

Install Visual Studio 2013 Update 2 RTM:
May 26, 2014 at 11:18 AM
Sorry. To fast :-).

I install the update and will be back with an answer.
May 26, 2014 at 12:22 PM
There are no changes in code. Not in Pleasewaitservice and also not in TabControl.
But: They are both moved to a shared project. I don't why it makes problems but it does.
May 26, 2014 at 12:34 PM
May 27, 2014 at 7:22 AM
Oh that much changes in the tabcontrol.

So for me its not clear why : "Add SingleUnloadOthers to TabControl so only a single view model lives in a tabcontrol". Thats the normal behavior.
Use the standard Tabcontrol of WPF. Or set single Loadbehavior and set CloseViewModel on unloaded.

Why add a behavior that is not needed and indeed don't test again the behavior that is realy needed. The only reason why this tabcontrol is created.

Sorry. My opinion.
May 27, 2014 at 8:08 AM
Because I didn't want to have to change between TabControl and Catel TabControl to check out the differences. It should support all.
May 27, 2014 at 8:34 AM
Yes it sould support all. Thats ok.
Use "Single Loadbehavior and set CloseViewModelOnUnload". Thats the same as "SingleUnloadOthers".

But more important is that the other behaviors should work.
May 28, 2014 at 6:51 AM
Edited May 28, 2014 at 6:55 AM
Add a issue