0

Is it possible to set a CanExecute on an InteractionTrigger?

This is my code, but I know in some instances the ButtonCommand will be NULL, So I want to be sure that I do not cause any issues.

<i:Interaction.Triggers>
  <i:KeyTrigger Key="Return">
    <i:InvokeCommandAction Command="{TemplateBinding ButtonCommand}" />
  </i:KeyTrigger>
</i:Interaction.Triggers>

Many thanks

2
  • 1
    Maybe you could use the IsEnabled property of InvokeCommandAction for that? Commented Dec 4, 2023 at 13:10
  • 2
    If the command is null, does anything bad actually happen? Commented Dec 5, 2023 at 17:33

1 Answer 1

1

If and when ButtonCommand is null, the Command property of the InvokeCommandAction will also be set to null and since the implementation checks the reference before trying to invoke the command you won't get any NullReferenceException.

So you don't have to do anything at all. This should work as expected out of the box.

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

Comments

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.