In my application we add programatically ContentPanes. If in the content pane we have an operation undergoing, we want to disable the close button of the ContentPane, until the operation undergoing finishes. For that we use AllowClose property. This works fine most of the time. But there are cases when we switch the value for AllowClose property from false to true quite fast. In those cases the close button remains disabled even though we have set the AllowClose to true. The close button becomes enabled only after we click on the content pane. Can you help me with this problem, or is this a limitation of the layout of the content pane control?
The development team gave me some tips on what is going on in this scenario :
This behavior is caused because the Close button is linked to a routed command. When
a commandsource like a Button is associated with a command it hooks its
CanExecute. In the case of routedcommands that means they are hooking the
CommandManager-> RequerySuggested event. The
WPF framework explicitly raises that event when you press the mouse button down
or press a key which is why it “works” usually.
What you can do to resolve this is to call
the CommandManager->InvalidateRequerySuggested to have the commands requery
the CanExecute state of the commands
Hello, your suggestion worked for all the cases I needed. Thanks a lot.