Home > database >  Caliburn how to load data when app is starting?
Caliburn how to load data when app is starting?

Time:03-29

Net6. I'd like to show MessageBox after long operation (e.g. fetching data) when app is starting.

  • In version 3.2.0 this works fine. When app is starting, main view shows up, then MessageBox is made visible.
  • In version 4.0.173 this doesn't work: MessageBox is visible and blocks main view.

My code:

Caliburn.Micro 3.2.0
    internal class ShellViewModel : Screen
    {
        protected override async void OnInitialize()
        {
            base.OnInitialize();
            await Task.Delay(1000);
            System.Windows.MessageBox.Show("hello");
        }
    }
    
Caliburn.Micro 4.0.173
    internal class ShellViewModel : Screen
    {
        protected override async Task OnInitializeAsync(CancellationToken cancellationToken)
        {
            await base.OnInitializeAsync(cancellationToken);
            await Task.Delay(1000);
            System.Windows.MessageBox.Show("hello");
        }
    }

CodePudding user response:

I've solved this problem by event Loaded: view:

xmlns:cal="http://caliburnmicro.com"
cal:Message.Attach="[Event Loaded] = [Action Window_Loaded()]"

vm:

    public async Task Window_Loaded()
    {
        await Task.Delay(1000);
        System.Windows.MessageBox.Show("hello");
    }
  • Related