Caliburn.Micro基于约定的绑定在嵌套视图中不起作用? [英] Caliburn.Micro convention-based bindings not working in nested views?

查看:67
本文介绍了Caliburn.Micro基于约定的绑定在嵌套视图中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整理这个Caliburn.Micro示例项目,但是在使用带有嵌套视图/视图模型的基于约定的绑定时遇到了麻烦。

I have this Caliburn.Micro sample project I'm putting together and I am having trouble with the convention-based bindings with nested views/viewmodels.

举个例子,假设我有一个Shell视图ShellView,它由作为屏幕导体的ShellViewModel支持。

As an example, let's say I have a shell view, ShellView, backed by ShellViewModel which is a screen conductor.

我在ShellView中有一个绑定到ActiveItem的内容控件(使用x:Name约定),并且ActiveItem的类型为EmployeeListViewModel,因此生成的视图为EmployeeListView。嵌套在此视图中的是一个由EmployeesDetailsViewModel支持的EmployeeDetailsView,该EmployeeDetailsViewModel绑定到EmployeeListViewModel中的所选项目。

I have a content control in the ShellView bound to ActiveItem (using the x:Name convention), and the ActiveItem is of type EmployeeListViewModel, so the resulting view is EmployeeListView. Nested in this view is an EmployeeDetailsView backed by an EmployeesDetailsViewModel which is bound to the selected item in EmployeeListViewModel.

这很好,除了在EmployeeDetailsView中我无法绑定东西例如使用Caliburn约定的文本框和按钮。效果很好:

This works fine, except that in EmployeeDetailsView I can't bind things like text boxes and buttons using the Caliburn conventions. This works fine:

<TextBox Text="{Binding EmployeeID}" />

但这两个行都不起作用:

but neither of these lines work:

<TextBox x:Name="EmployeeID" />
<Button x:Name="ClickMethod" />

文本框文本绑定并不重要,但是自动按钮方法连接是其中之一关于Caliburn.Micro的最酷的东西,但它似乎无法在嵌套视图中使用。

The text box text binding isn't a big deal but the automatic button method hookup is one of the coolest things about Caliburn.Micro, but it doesn't seem to work in nested views.

有任何想法吗?

推荐答案

当您将EmployeesDetailsViewModel(SelectedItem)绑定到您正在手动执行的EmployeesDetailsView上时,我有一种感觉。 CM当时还没有做好任何准备。可以将xaml和一些CS发布到SelectedItem绑定中吗?您是否尝试

I have a feeling that you when you are binding the EmployeesDetailsViewModel (SelectedItem ) to the EmployeesDetailsView that you are doing it manually. CM isn't wiring things up at that point. Can you post the xaml and some cs for the SelectedItem binding? Did you try

<MyUc:EmployeesDetailsView x:Name="SelectedEmployee" />

然后将SelectedEmployee挂在EmployeeListViewModel上吗?

And hang a SelectedEmployee off the EmployeeListViewModel?

这篇关于Caliburn.Micro基于约定的绑定在嵌套视图中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆