开发者

Caliburn Micro WPF Window Management

开发者 https://www.devze.com 2023-03-28 06:41 出处:网络
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

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.

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"));
    }
}

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)

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");
    }
}

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 tha开发者_运维知识库t the framework conventions that I used on WP7 would have transferred a tonne better than it seems to be.

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


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

you can download it here: http://caliburnmicro.codeplex.com/releases/view/70940

0

精彩评论

暂无评论...
验证码 换一张
取 消