MemBus + Caliburn.Micro = Lean Screen

To be honest, without this blog post on Caliburn.Micro I was kind of stuck. But now I ended up with my Screen conductor, and it’s likely that it is not going to change a lot:

[Single]
public class ShellViewModel : Conductor<Screen>
{
    private readonly IDisposable screenStreamDispose;

    public ShellViewModel(IObservable<RequestToActivateScreen> screenStream)
    {
        screenStreamDispose = screenStream
            .SubscribeOnDispatcher()
            .Where(msg=>msg.ScreenAvailable)
            .Subscribe(onNextScreenRequest);
    }

    private void onNextScreenRequest(RequestToActivateScreen request)
    {
        ActivateItem(request.Screen);
    }

    protected override void OnDeactivate(bool close)
    {
        screenStreamDispose.Dispose();
        base.OnDeactivate(close);
    }
}

The Observable is constructed based on MemBus. The screenStream is shaped with the aid of the reactive framework while “ActivateItem” loads the corresponding view for the given Screen. Overriding OnDeactivate gives a nice place to dispose of a subscription. The whole code is to be found in the MemBus “Hello World” App.

Chronology

  |  
comments powered by Disqus