How can CanExecute from the command line come on after removing an item from the visual tree?

I have a related question here , where I have a custom control bound to a command. The user control is removed from the visual tree, but canExecute still works. My understanding of the Commanding model was that it bubbles and tunnels are like smashed events. So, how can you fry CanExecute once the item with the command binding is no longer in the visual tree?

+3
source share
2 answers

My Guess is an instance of a command registered with the commandmanager. Commands can be executed from different sources, and not just for user interfaces, for example, keyboard shortcuts.

Try calling CommandManager.InvalidateRequerySposed (); and add a breakpoint to the canexecute method to confirm that it is.

Hope this helps.

+1
source

IMO, CommandBindings are really poorly implemented in WPF. You have to get around the fact that the system retains the WeakReference value for your control if it has a CommandBinding, even when the control is closed.

, CommandBinding XAML. , , . CommandBindings . , .

:

A) CommandBindings XAML. . , InitializeComponent(). this.CommandBindings.Add(), CommandBindings .

B) Closed() this.CommandBindings.Clear().

, CommandBindings . , , Microsoft. , - CommandBindings XAML, .

+1

Source: https://habr.com/ru/post/1727993/


All Articles