MariaSnuggles
MariaSnuggles

Reputation: 203

Do I have need for a screen conductor (Caliburn Micro)

I'm working on a single form application where I intend to open modal dialogs only. Its purpose is mostly taking input from the user to create objects to store in a database.

  1. Do I have need for a screen conductor or will a Window Manager suffice? I've tried reading all I can on the subject but still I'm not sure.

    I would like the benefit of not closing down modal dialogs if a certain amount of data hasn't been filled in, so I assume this would be classed as life-cycle management, thus forcing me to use a conductor, or can just the Window Manager handle it? I was under the impression that anything that opens a new window can't be done with the conductor?

  2. Also, which is better in terms of wpf: I've read about passing an instance of the window manager to each class that needs it, but also about raising an event that one class listens for and opens a window as specified in the event. Would this latter be bad as it forms a tight relationship between each class and the event handling class?

Thanks

Upvotes: 4

Views: 2401

Answers (2)

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

  1. I would use a conductor here, and yes it can show modal dialogs. Take a look at the Billy Hollis Hybrid Shell article to see an example application where dialogs and dirty tracking (checking if a form has information to be saved) are used, and here is the link for the WPF application I modified which don't use MEF.
  2. If always prefer to pass my dependencies around and inject them through the constructors so I won't go with raising events unless I really need to, and anyway I would use the EventAggregator then and not normal .NET events, the first solution is better for testability and makes it clear what each part of the application needs and what it does.

Upvotes: 1

Oscar Mateu
Oscar Mateu

Reputation: 809

I'm pretty new at this but I will try to be helpful: when you run an application built with Caliburn Micro, the Window Manager is automatically used to create the startup window. Regarding the bootstrapper:

    protected override void Configure()
    {
    container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));

    CompositionBatch batch = new CompositionBatch();

    batch.AddExportedValue<IWindowManager>(new WindowManager());
    batch.AddExportedValue<IEventAggregator>(new EventAggregator());
    batch.AddExportedValue(container);

    container.Compose(batch);
  }

You can use this instance of the window manager to manage the different dialogs. Then you just have to import the window manager in the view model needed:

private readonly IWindowManager _windowManager;


[ImportingConstructor]
public FooViewModel(IWindowManager windowManager)
{
  _windowManager = windowManager;
}

Please take a look at the samples of the caliburn micro documentation (http://caliburnmicro.codeplex.com/documentation) and also at this blog: http://www.mindscapehq.com/blog/index.php/2012/03/13/caliburn-micro-part-5-the-window-manager/

The communication between viewmodels is done by the event aggregator.

Upvotes: 0

Related Questions