Caliburn.Micro getting it to bind UserControls in a MainView to their ViewModels

你离开我真会死。 提交于 2019-12-02 23:22:31
EisenbergEffect

You don't need to use a Conductor here. That's basically used for navigation scenarios. Just make two public properties on your MainViewModel one for RightSideControlViewModel called RightSide and one for LeftSideControlViewModel, called LeftSide. Then, instead of instantiating your UserControls directly in your MainView, create two ContentControls, one with x:Name="LeftSide" and the other with x:name="RightSide" This is a view-model-first way of accomplishing it. If you want to do it view-first, keep the user control definitions in your MainView, but change the Bind.Model so that it points to the new properties you created, like Bind.Model="{Binding LeftSide}"

Basically, the way you have things defines....the bindings just aren't pointing at the right objects, more or less. You've got the Conductor in there, which you don't need to accomplish this. You may want to keep it if you intend to have some sort of navigation architecture. Remember that when you call ActivateItem on a Conductor, you are basically changing its ActiveItem property; only one model with be active at a time. In the case above you activate both items, but only the second one remains active. Furthermore, in your view, nothing is bound to ActiveItem.

I hope this makes sense!

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