Loading view data, IResult and OnInitialize

Topics: Actions & Coroutines
Jun 20, 2012 at 1:24 PM


I am new to Caliburn and trying to figure out what the correct / best way is to load data into a view. I have a basic view which inherits from Screen.

When I create the view I want to be able to load the data for 3 combos that are displayed on the view. Would the right way to do this be by overriding OnInitialize?

How would I go about making this async?


Jun 21, 2012 at 9:47 AM

Yes, OnInitialize would be the right way. OnInitialize executes only when the VM is activated the first time. Another opportunity would be OnActivate, which executes every time the VM is activated, or OnViewLoaded, which executes when the view's loaded event fires. Use OnViewLoaded if you have to interact directly with the view (eg if you want to start an animation from the VM).

You would make this async by creating an IResult, that does the work, and call it in the OnInitialize method with:

Caliburn.Micro.Coroutine.BeginExecute((new[] { new MyWorkCoroutine() }).GetEnumerator());

Or, to make live easier and code more readable, you create a method that returns the coroutine(s) that should be executed:

private IEnumerable<IResult> GetData(){
    yield return new MyWorkCoroutine();

public override void OnInitialize(){

Hope this helps,


Jun 21, 2012 at 9:18 PM

Hi Roland

That really clears it up. Thank you very much.