0

another day, another problem. Honestly, it would be rather boring if this ever stopped, wouldn't it?

EDIT : Seems all of the background-information is obsolete. Here's the boiled down version: My Command class rigs up CanExecuteChanged with the CommandManagers RequerySuggested event (as described here : WPF Custom ICommand implementation and the CanExecuteChanged event).

public abstract class CommandBase : ICommand
{
    public abstract void Execute(object parameter);
    public abstract bool CanExecute(object parameter);
    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }
}

In my case, the CommandManager fails to suggest a requery where it would be of some importance. Now I have to bypass this and force it to requery. Does anybody know how to do this?

Another Edit: I've tried really many things now (changing my command logic, removing control template and style), and still get stuck on this. I can't reproduce the problem in an isolated sandbox scenario, though. I really think I am suffering from a bug here, since the Button's behaviour is inconsistent with its looks, even if the Style is boiled down to the following :

<Style TargetType="{x:Type Button}" x:Key="CertificateActionButton">
    <Setter Property="Background" Value="{DynamicResource CertificateActionButtonBackground}"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Background" Value="LightGray"/>
        </Trigger>
    </Style.Triggers>
</Style>

When I unfocus and then focus the window again, Coherence is restored - the button the looks as inactive as it is.

Update : Since I haven't been able to reproduce this issue, i close this question. The only answer it has received was a good one, but after having edited the question so many times, q & a don't really seem related any more.

Community
  • 1
  • 1
Sebastian Edelmeier
  • 4,095
  • 3
  • 39
  • 60

1 Answers1

1

You could try calling CommandManager.InvalidateRequerySuggested() from here.

The CommandManager only pays attention to certain conditions in determining when the command target has changed, such as change in keyboard focus. In situations where the CommandManager does not sufficiently determine a change in conditions that cause a command to not be able to execute, InvalidateRequerySuggested can be called to force the CommandManager to raise the RequerySuggested event.

also from the notes:

It should be noted, that if you are using async calls, then the CommandManager.InvalidateRequerySuggested() should be called from the main thread, as any command listeners will be on the UI thread. (Use a Dispatcher and call CheckAccess())

Mark Staff
  • 721
  • 3
  • 6
  • Thanks mark, I think this would have worked if it weren't a completely different issue that was bothering me. Please see my edits above for updates. – Sebastian Edelmeier May 31 '11 at 13:14