Caliburn.Micro:以编程方式创建和绑定视图 [英] Caliburn.Micro: Create and Bind View programmatically

查看:304
本文介绍了Caliburn.Micro:以编程方式创建和绑定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Caliburn.Micro中尝试视图组合。我有一个工作示例,其中通过 View.Model附加属性路由将多个基于用户控件的视图注入到主外壳中。到目前为止,一切都很好。

I am currently experimenting with view composition in Caliburn.Micro. I have a working example where I have multiple user control based views injected into my main shell via the "View.Model" attached property route. So far so good.

在我的应用程序中,我使用的主要是WinForms和一些WPF的混合环境,因此,对于Caliburn没有WPF的外壳管理。我希望能够按需创建视图并将其添加到WinForms应用程序的占位符中。

In my application proper I am working with a mixed environment of mainly WinForms, with some WPF, so there is no WPF "shell" for Caliburn to manage. I'd like to be able to create my views on demand and add them to placeholders in my WinForms app.

我想知道如何使用Caliburn以编程方式创建视图(将是包含子用户控件的用户控件),以便所有约定,模型绑定和

I would like to know how I go about creating a view (which will be a user control containing sub user controls) programmatically using Caliburn so that all conventions, model bindings and sub-view injection is carried out.

推荐答案

Caliburn ViewModelBinder 可以一旦有了视图实例和相应的视图模型,就可以用来摇柄。调用 Bind 可以解析注入的视图并应用基于约定的绑定,等等:

The Caliburn ViewModelBinder can be used to crank the handle once you have a view instance and a corresponding view-model. Calling Bind resolves injected views and applies convention based binding, etc:

    SomeCompositionView view = new SomeCompositionView();

    ISomeCompositionViewModel viewModel = IoC.Get<ISomeCompositionViewModel>();

    ViewModelBinder.Bind(viewModel, view, null);

    ElementHost.Child = view;  

这篇关于Caliburn.Micro:以编程方式创建和绑定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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