ActionMessage and Referenced Objects

Apr 27, 2011 at 8:24 AM

Hello,

I'm using ActionMessage in my project more often now but since I added controller objects to it, I also want to call methods on
the controller object which are reference from the viewmodel. I tried to use the following syntax which leads into a excpetion:

<Button Grid.Row="0" Grid.Column="4" VerticalAlignment="Center" HorizontalAlignment="Right"  Content="...">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <cal:ActionMessage MethodName="ImpotController.SelectNewImportPath" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

So I create a dummy-method in the viewmodel which reroutes the call into the controller, which seems a bit annoying to me.
Is there a way to get around this??

Apr 27, 2011 at 8:36 AM

You need to define the controller as the target of your message.

By default the target is the DataContext, but you can change it anytime (affecting or not the DataContext):

<Button Grid.Row="0"
        Grid.Column="4"
        VerticalAlignment="Center" HorizontalAlignment="Right"
        Content="..."
        cm:Action.TargetWithoutContext="{Binding Path=ImpotController}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <cal:ActionMessage MethodName="SelectNewImportPath" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

Apr 28, 2011 at 4:14 PM

Works perfectly. Thanks for the info.