Caliburn.Micro convention-based bindings not working in nested views?

主宰稳场 提交于 2019-12-07 11:12:38

问题


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.

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

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.

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" />

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.

Any ideas?


回答1:


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" />

And hang a SelectedEmployee off the EmployeeListViewModel?



来源:https://stackoverflow.com/questions/4211624/caliburn-micro-convention-based-bindings-not-working-in-nested-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!