.net - Can't subscribe to DelegateCommand.CanExecuteChanged -
I have two ViewModels and one of them is second in the Microsoft. Practice. Prism Commands Delayed Commands is called PrintCommand . This part of the order of CanExecuteChanged desirable to subscribe to the event has always been applied like:
OneViewModel.PrintCommand.CanExecuteChanged + = CanExecuteChangedHandler; The problem is that this membership does not work. Decompiled CanExecuteChanged looks like this:
public function eventhandler CanExecuteChanged {{add WeakEventHandlerManager.AddWeakReferenceHandler (reference this._canExecuteChangedHandlers, value, 2); } Remove {WeakEventHandlerManager.RemoveWeakReferenceHandler (this._canExecuteChangedHandlers, value); }} When I pause a live operators after a couple of after debug, subscription steps _canExecuteChangedHandlers , even if the client object still exists Does not seem to have
I'm curious, why is this happening?
After the text the answer was found in the description of That means we have to be a difficult context: and thus use it: CanExecuteChanged . The message is:
/// when subscribing & lt to see cref = "e: System.Windows.Input.ICommand.CanExecuteChanged" / & gt; Event using the /// code (when binding on using XML) will require a hard reference for the event handler. This is to stop the /// garbage collection of the event handler because the command implements weak event patterns, so this is not a difficult reference for /// this handler. The example implementation can be seen in composite commands and commandbackbusiness /// sections. In most scenarios, there is no reason to sign up directly at the Kenxaxite changelog event, but if you do, then you are responsible for maintaining /// reference.
private Reedonli Iventhaandlr Kmmandaksaksaktekcanghedlr;
this.commandCanExecuteChangedHandler = new eventhandler (this.CommandCanExecuteChanged); This.command.CanExecuteChanged + = this.commandCanExecuteChangedHandler;
Comments
Post a Comment