Caliburn.Micro 中单个视图中的两个动态分配的 ContentControl
我有一个 UserControl,其中包含两个 ContentControl,这两个 ContentControl 需要在运行时将不同的 UserControl 视图绑定到它们。此处提到的附加属性解决方案确实如此似乎在 Silverlight 中不起作用。或者,我做错了什么。我还发现这个< /a>,但也没有带来任何快乐。
我有一个 ContentControl,将其命名为“ActiveItem”。但是,当然,我不能有两个同名的 ContentControl。
预先感谢您的帮助,
吉姆
I have a UserControl that contains two ContentControls that need to have different UserControl Views bound to them at runtime. The attached-Property solution noted here does not seem to work in Silverlight. Or, I am doing something wrong. I also, found this, but it did not bring any joy either.
I had a single ContentControl working by naming it 'ActiveItem'. But, of course, I cannot have two ContentControls with the same name.
Thanks in advance for any help,
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在主视图模型上公开两个公共属性,每个属性都是您希望显示的视图模型类型的实例。然后,在您的视图中有一个具有相应名称的
ContentControl
。例如:Just expose two public properties on your main view model, each one being an instance of the type of view model you wish to display. Then, in your view have a
ContentControl
with the corresponding name. E.g:这是一个老问题,但如果有人遇到同样的问题,我在这里发布我从一开始就以更彻底的方式处理它的方法:
Caliburn.Micro.Conductor.Collection.AllActive
;Caliburn.Micro.Screen
;ActivateItem(MenuUC)
和DeactivateItem(MenuUC)
。 Caliburn.Micro 会自动检测您想要使用哪一个。在上面的示例中,
ChangePanels()
充当将新用户控件加载到 ContentControl 中的方法。另请阅读这个问题,它可能会进一步帮助您。
This is an old question, but in case anyone is having the same issue, I post here my way of handling it from the beginning and in a more thorough manner:
Caliburn.Micro.Conductor<Screen>.Collection.AllActive
;Caliburn.Micro.Screen
;ActivateItem(MenuUC)
andDeactivateItem(MenuUC)
everywhere in your code. Caliburn.Micro automatically detects which one you want to work with.In the above example,
ChangePanels()
acts as a method to load new User Control into your ContentControl.Also read this question, it might be help you further.