我正在使用Caliburn.Micro编写WPF应用程序。我想基于带有复选框的列表框中的选中项目更新名称列表。
XAML:
<ListBox ItemsSource="{Binding Names}">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate>
<CheckBox Content="{Binding Value}" IsChecked="{Binding IsChecked}" />
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
IsChecked绑定有效,因此我可以运行一种方法来验证已检查的元素并更新名称列表。我的第一种方法是将命令绑定到复选框Click事件或Checked / Unchecked,但是我无法使其正常工作...
<CheckBox Content="{Binding Value}" IsChecked="{Binding IsChecked}" Click="{Binding UpdateNameList}" />
在我的ViewModel中:
public void UpdateNameList()
{
// update list...
}
我在运行时收到此错误:
error Unable to cast object of type 'System.Reflection.RuntimeEventInfo' to type 'System.Reflection.MethodInfo'.
如何使用Caliburn.Micro绑定到复选框单击事件?还是应该以其他方式执行此操作?
谢谢
使用Action.TargetWithoutContext
附加属性将Action.Target绑定到父视图模型,并使用Message.Attach
连接该方法。这应该工作:
您需要具有正确的签名才能起作用。