如何使用 CaliburnMicro 在 Shell 的不同 ContentControls 中加载控件
默认情况下,当您使用“ActivateItem(new Control());”时您的控件被加载到名为 ActiveItem 的 ContentControl 中,例如。 。如果我的页面上有多个内容控件,我将如何将控件加载到其中,同时保留使用能够将控件加载到活动项控件的默认功能的能力。
例如,我希望将登录控件加载到登录 ContentControl 中,当用户成功登录时,我希望将新控件加载到 ActiveItem ContentControl 中。
提前致谢。
By default when you use "ActivateItem(new Control());" your control is loaded into a ContentControl which with the name ActiveItem, fro example. . If I have multiple content controls on my page how would I load controls into them whilst retaining the ability to use the default functionality of being able to load controls into the the active item control.
for example I want to have a login control to be loaded into the Login ContentControl, and when a user successfully login I want a new control to be loaded into the ActiveItem ContentControl.
Thanx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果绑定到 UI 的 ViewModel 包含名称与内容控件匹配的属性。如果此属性本身是 ViewModel 类型并且已注册到 Ioc 容器,则内容控件视图会自动解析此属性支持的视图。例如
如果主ViewModel上有一个属性LoginStatus(LoginStatus属性本身就是一个ViewModel)。内容控件将使用适当的视图正确呈现。
If the ViewModel that gets binded to the UI contains a property with the name that matches a content control. The Content control view automatically gets resolved the the view supported by this property, provided this property itself is a ViewModel type and has been registed with Ioc container. For example
If there is a property LoginStatus on the main ViewModel (LoginStatus property itself is a ViewModel). The content control would correctly get rendered with the appropriate view.
这是一个老问题,但如果有人遇到同样的问题,这是我的解决方案:
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, here is my solution:
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.
您应该看看屏幕导体。请参阅此处。
You should have a look at Screen Conductors. See here.