我遇到了使用caliburn ActionMessage和Windows Phone 8.1的问题。这是我的代码:
<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>
在我的应用程序中,按钮将在运行时创建。但是当我按下按钮时,我有这个错误:
System.Exception:找不到方法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) 在Microsoft.Xaml.Interactions.Core.EventTriggerBehavior.OnEvent(Object sender,Object eventArgs)
为什么呢?使用WP 8.0,此代码可以正常工作。
谢谢!
答案 0 :(得分:1)
您必须在ActionMessage上指定AssociatedObject
。在你的情况下,这是按钮。
以下问题描述了详细信息: https://github.com/Caliburn-Micro/Caliburn.Micro/issues/24
答案 1 :(得分:0)
此异常的另一个原因可能是。
@Max描述的异常,如果你没有注册你的viewmodel也会发生:
_container = new WinRTContainer();
_container.RegisterWinRTServices();
_container.PerRequest<TestViewModel>(); // <-- without that line I got the same error
PS:适用于Caliburn.Micro v.2.0.1