Guard method only evaluated once within a DataTemplate

Topics: Actions & Coroutines
Jun 26, 2013 at 12:35 PM
I have a ContentControl which uses DataTemplates to display it's content. Such a DataTemplate looks like this:
<DataTemplate DataType="{x:Type testCase:Foo}">
    <Border Background="CornflowerBlue">
            <TextBlock Text="{Binding}" />
            <Button cal:Action.TargetWithoutContext="HitMeCommand" 
                   Hit me!
When I hit the button, Execute(...) is called with the correct DataContext, but the problem is, that the CanExecute(...) guard method only gets evaluated once. If I change the Content of the ContentControl to another Foo instance, then CanExecute(...) is not evaluated again.

A tiny sample project is available here:
Jun 26, 2013 at 1:04 PM
An action guard declared as a function is only re-evaluated if their parameters change.
In your case I fear that the action parameter, initialized with the special value, is not updated.
Try to avoid the short syntax, and use the full one, defining the action parameter using a binding.
Jun 27, 2013 at 9:20 AM
Thanks! This works just fine:
<Button cal:Action.TargetWithoutContext="HitMeCommand">
    Hit me!
        <i:EventTrigger EventName="Click">
            <cal:ActionMessage MethodName="Execute">
                <cal:Parameter Value="{Binding}" />