Caliburn Micro WPF窗口管理 [英] Caliburn Micro WPF Window Management

查看:183
本文介绍了Caliburn Micro WPF窗口管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用caliburn.micro启动WPF应用程序,以便尽可能多地使用TDD,之前在WP7中使用过caliburn.micro,但WPF似乎与众不同,而文档则是

I'm wanting to start a WPF application using caliburn.micro so I can use TDD as much as possible, I've used caliburn.micro before with WP7 but WPF seems to be a different ship, and the documentation isn't as complete as that for WP7.

我已经用Bootstrapper设置了项目

I've set up the project with my Bootstrapper

public class ApplicationBootstrapper : Bootstrapper
{
    private SimpleContainer _container;
    private WindowManager _windowManager;

    protected override void Configure()
    {
        _container = new SimpleContainer();
        _windowManager = new WindowManager();

        _container.RegisterSingleton(typeof(MainViewModel), "MainViewModel", typeof(MainViewModel));
        _container.RegisterSingleton(typeof(DataViewModel), "DataViewModel", typeof(DataViewModel));

    }

    protected override object GetInstance(Type service, string key)
    {
        return _container.GetInstance(service, key);
    }

    protected override IEnumerable<object> GetAllInstances(Type service)
    {
        return _container.GetAllInstances(service);
    }

    protected override void BuildUp(object instance)
    {
        _container.BuildUp(instance);
    }

    protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
    {
        _windowManager.ShowWindow(_container.GetInstance(typeof(MainViewModel), "MainViewModel"));
    }
}

这会加载MainView的罚款,这让我觉得我赢了,但是当时我想继续前进,并进行另一个视图/视图模型设置,但是为了我的生命,我无法让WindowManager传递给我的ViewModel来加载更多视图(就像我对NavigationService所做的那样) WP7)

and this loads the MainView fine, which made me think I had won but I was then wanting to move on and have another view/viewmodel setup but for the life of me I cannot get the WindowManager to be passed through to my ViewModel in order to load more views (As I did with the NavigationService in WP7)

这是我的MainViewModel代码

Here is my MainViewModel code

public class MainViewModel : BaseViewModel
{
    private readonly DataViewModel _dataViewModel;
    private readonly IWindowManager _windowManager;


    public MainViewModel(IWindowManager windowManager, DataViewModel dataViewModel)
    {

        _dataViewModel = dataViewModel;
        _windowManager = windowManager;
    }

    public string Title { get { return ApplicationTitle; } }

    public void BtnNew()
    {
        System.Diagnostics.Debug.WriteLine(_windowManager == null);

    }

    public void BtnLoad()
    {
        MessageBox.Show("Sorry, not yet implemented");
    }
}

但是Window Manger和DataViewModel始终为null,当我在互联网上搜索解决方案时,我发现确实是我想利用的WindowManager,以及有关MEFBootStrapper的信息?但是我本以为我在WP7上使用的框架约定会比看起来好得多。

But the Window Manger and the DataViewModel is always null, when I searched the internet for a solution I found that it was indeed the WindowManager that I wanted to utilize, and something about the MEFBootStrapper? but I would have thought that the framework conventions that I used on WP7 would have transferred a tonne better than it seems to be.

简单容器只是食谱,由caliburn.micro在其网站上提供,我在WP7应用程序中使用了

The Simple Container is just the recipe provided by caliburn.micro on their site, and the one I used in WP7 applications

推荐答案

您没有在IOC容器中注册WindowManager。
看看Caliburn.Micro.HelloWindowManager示例项目。

you didnt register the WindowManager with the IOC container. take a look at Caliburn.Micro.HelloWindowManager sample project.

您可以在此处下载:
http://caliburnmicro.codeplex.com/releases/view/70940

这篇关于Caliburn Micro WPF窗口管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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