How to clear command bindings registered by CommandManager?

I have this control (WPF) that uses CommandBinding and registers as follows:

CommandBinding binding = new CommandBinding(ApplicationCommands.Delete, OnDeleteExecuted, CanExecuteDelete); CommandManager.RegisterClassCommandBinding(typeof(MyObject), binding); 

So, when I unload the control, I want to clear this binding. How can i do this?

Thanks!

+4
source share
2 answers

If the scope of the commands is a specific UIElement, it is better to use:

  • Register CommandBinding: myUIelement.CommandBindings.Add (myCommand);
  • Unregister CommandBinding: myUIelement.CommandBindings.Remove (myCommand);
  • Unregister all CommandBindings: myUIelement.CommandBindings.Clear ();

Hope this helps.

+4
source

All Articles