Search code examples
c#xamlwindows-phonewindows-phone-8.1caliburn.micro

Caliburn 2.0.0 and WP 8.1 : ActionMessage don't found target method


I've a problem with caliburn ActionMessage and windows phone 8.1 . Here my code:

       <ListBox x:Name="Categories" Grid.Row="1" ItemContainerStyle="{StaticResource TileListBoxItemStyle}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Button>
                    <i:Interaction.Behaviors>
                        <core:EventTriggerBehavior EventName="Click">
                            <micro:ActionMessage MethodName="GoToPage">
                                <micro:Parameter Value="{Binding Path=PageId}" />
                            </micro:ActionMessage>
                        </core:EventTriggerBehavior>
                    </i:Interaction.Behaviors>
                    <TextBlock Text="{Binding Path=PageDescription}" TextWrapping="Wrap"
                           HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Button>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

On my app, the buttons will be created at runtime. But when I press button, I have this error:

System.Exception: No target found for method GoToPage. at Caliburn.Micro.ActionMessage.Invoke(Object eventArgs) at Caliburn.Micro.TriggerAction`1.Execute(Object sender, Object parameter) at Microsoft.Xaml.Interactivity.Interaction.ExecuteActions(Object sender, ActionCollection actions, Object parameter) at Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender, Object eventArgs)

Why? With WP 8.0 this code works.

Thanks!


Solution

  • You have to specify AssociatedObject on the ActionMessage. In your case this is the button.

    Following issue describes the details: https://github.com/Caliburn-Micro/Caliburn.Micro/issues/24