The CommandManager that never dies…and ends up on Codeplex…

The other day, a reader called MAX pointed out to me that the CommandManager has a major flaw. It stores all commands in a static list. This keeps the garbage collection from working as it should, as the commands are always referenced. The commands in turn reference the controls that use them. So the CommandManager actually keeps any control that uses commanding from being GC:ed. So, because of this, I have changed the CommandManager code once more. This time however, I have not just added some information here and posted the new code for download. Instead, since the CommandManager seems to never die, I have put it on Codeplex making it available at http://agcommandmanager.codeplex.com.

The CommandManager never dies? …have I forgotten about Silverlight 4? No, not at all. Silverlight 4 has a bit of commanding built into it. It supports binding ICommands to Command properties on some controls, such as Buttons. This is great and will definitely limit the need for the CommandManager. The CommandManager has one thing that Silverlight 4 does not have. It supports binding ICommands to more or less any event. So if anyone needs this kind of flexibility, the CommandManager is the way to go…

Comments (3) -

Hi,

I am trying to implement your code for command manager instead of implement third party tools like Prism. I have downloaded your latest code from the codeplex. I need how to link the event handler methods in my pageViewmodel. For example I have two dropdown boxes. onchange of the first dropdown box, I want to invoke a event handler with a string parameter(Selected value of the combobox), so that I can reload the values in the second combo box.

Thanks in advance..

btw, I am using silverlight 3

Hi Valar!
The xaml for that would look something like this...

<ComboBox x:Name="box1"
cmd:CommandManager.EventName="SelectionChanged"
cmd:CommandManager.Command="{Binding MyCommand}"
cmd:CommandManager.CommandParameter="{Binding SelectedItem, ElementName=box1}">
  ...values...
</ComboBox>

I haven't tried the above, but it should work I think. Just remember to declade the cmd xml-namespace at the top of the page and expose an ICommand called MyCommand in your VM...
Cheers,
Chris

Comments are closed