Windows Phone Caliburn Micro HyperLink单击事件
问题描述:
我正在使用Caliburn Micro作为Windows Phone应用程序。我有一个超链接控件,我想将click事件绑定到View Model。下面是示例代码Windows Phone Caliburn Micro HyperLink单击事件
XAML,MyPage.xaml
<TextBlock>
<Run>Got to</Run>
<Hyperlink micro:Message.Attach="[Event Click] = [Action OpenAnotherPage]">
My Page</Hyperlink><Run Text="."></Run></TextBlock>
视图模型MyPageViewModel.cs
public void OpenAnotherPage()
{
// some code
}
当我的链接点击,我得到一个异常
系统.Exception:没有找到方法的目标
可能是什么问题?
更新1:尝试了超链接控制设置micro:Action.TargetWithoutContext="{Binding ElementName=MyPage, Path=DataContext}"
,但没有奏效
答
给TextBlock的名称,并用其作为的ElementName,因为你有超链接嵌套入控制。然后Update1应该工作。
答
尝试下面的XAML(未经测试):
<Hyperlink>My Page
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<ec:CallMethodAction TargetObject="{Binding}" MethodName="OpenAnotherPage" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Hyperlink>
的命名空间下(你需要引用这些组件2,他们是由微软与MS的Expression Blend运)
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
试过了,但得到了同样的错误 –