79767820

Date: 2025-09-17 21:24:36
Score: 1
Natty:
Report link

Did none of the other XAML solutions work for you?

Do you reject the flicker that IsAsync causes?

Do you detest workarounds in C#?

Set CommandParameter as an attribute, and Command in a style.

For instance, instead of this:

<Button
    CommandParameter="{Binding .}"
    Command="{Binding Source={SOME_SOURCE}, Path=SOME_PATH}"
</Button>

Use this:

<Button
    CommandParameter="{Binding .}"
    <Button.Style>
        <Style TargetType="Button">
            <Setter Property="Command" Value="{Binding Source={SOME_SOURCE}, Path=SOME_PATH}"/>
        </Style>
    </Button.Style>
</Button>

Why does this work?

I'm guessing that different types of bindings are resolved at different times, and CanExecute() is called on the bound Command object as soon as it's resolved - even if CommandParameter hasn't been resolved yet.

Styles use a different mechanism to set attributes. I imagine that this is resolved in a later step, meaning that CommandParameter is guaranteed to be resolved before Command.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Did
  • Low reputation (1):
Posted by: ator-dev