2

I have a button with a bound command and command parameter:

    <Button Margin="5,0,5,5" Style="{StaticResource MainButton}" Grid.Row="2" Grid.RowSpan="2" Grid.Column="3" Padding="0">
         <Button.CommandParameter>
              <MultiBinding Converter="{StaticResource SwapArgsConverter}" ConverterParameter="-1">
                   <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=tlq:SmartWarningsWindow}" Path="DataContext.SelectedWarning"></Binding>
                   <Binding Path="Rank"></Binding>
              </MultiBinding>
         </Button.CommandParameter>
         <Button.Command>
              <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=tlq:SmartWarningsWindow}" Path="DataContext.SwapCommand"></Binding>
         </Button.Command>
     </Button>

The bindings all work fine, but the Command binding resolves, and the ICommand.CanExecute method fires before the CommandParameter binding resolves. This is causing my control to be incorrectly disabled when the window loads.

I have tried several things, including placing the Command Binding after the CommandParameter binding like you see above (originally the command binding was an attribute).

Does anyone know a way to force the CommandParameter binding to resolve first?

1
  • Have you tried to re query in your command class? Commented Jun 12, 2015 at 20:52

1 Answer 1

1

You might be missing this in your command class:

public event EventHandler CanExecuteChanged
{
    add { CommandManager.RequerySuggested += value; }
    remove { CommandManager.RequerySuggested -= value; }     
}

An event is raised whenever the CommandManager thinks that changes had happened and will affect the ability of commands to execute.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the delay! This was the correct answer, I was pulled on to another project, and didn't get back to this till just now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.