سؤال

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!

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Another reason of this exception may be.

Exception that @Max has described, also occures if you did not register your viewmodel:

_container = new WinRTContainer();
_container.RegisterWinRTServices();
_container.PerRequest<TestViewModel>(); // <-- without that line I got the same error

PS: Valid for Caliburn.Micro v.2.0.1

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top