Show BusyIndicator from WPF.ExtendedToolkit in Caliburn.Micro

3k views Asked by At

Hi I try show busy indicator in shell which is wpf window.

In shell view I have this:

<Grid>
    <extToolkit:BusyIndicator IsBusy="{Binding Path=ShellIsBusy, Mode=OneWay,
                                            UpdateSourceTrigger=PropertyChanged}" 
                              BusyContent="{Binding Path=BusyMessage,Mode=OneWay,
                                                UpdateSourceTrigger=PropertyChanged}">
        <ContentControl x:Name="ActiveItem" />

     </extToolkit:BusyIndicator>
</Grid>

Shell model class is here:

[Export(typeof(IShellViewModel))]
public class ShellViewModel : Conductor<IScreen>.Collection.OneActive, 
    IShellViewModel,  IPartImportsSatisfiedNotification
{
    [Import]
    internal IJinglePlayer JinglePlayer { get; set; }

    private bool _isBusy;
    private string _busyMessage;

    public bool ShellIsBusy
    {
        get { return _isBusy; }
        set
        {
            _isBusy = value;
            NotifyOfPropertyChange(()=>ShellIsBusy);
        }
    }

    public string BussyMessage
    {
        get { return _busyMessage; }
        set
        {
            _busyMessage = value;
            NotifyOfPropertyChange(()=>BussyMessage);
        }
    }

    protected override void OnInitialize()
    {
        Show1();
        base.OnInitialize();
        JinglePlayer.PlayStartUp();
    }

    public void Show1()
    {
        var vm = IoC.Get<ILogOnViewModel>();
        ActivateItem(vm);
    }

    public void Show2(IAccount account)
    {
        ActiveItem.Deactivate(true);
        var vm = IoC.Get<IMeViewModel>();
        vm.Account = account;
        ActivateItem(vm);        }

    public void OnImportsSatisfied()
    {

    }
}

I run app, from active view model class I call this:

          [Import]
           internal IShellViewModel Shell { get; set; }

            //...

            Shell.ShellIsBusy = true;
            Shell.BusyMessage = "logging";

            //long task

            Shell.Show2(logOnResult.ReturnValue);

Problem is that busy indicator is showed in the moment when is active another view.

1

There are 1 answers

0
AudioBubble On

I post my solution, maybe someone will have better idea. Problem is that long running task keep UI thread busy, so I call this task and shell method on active new view in another thread.

Something like this:

Task.Factory.StartNew(() => { //long task });

Task.Factory.StartNew(() => { Shell.Show2(...); });

This unblock UI thread and BusyIndicator can be displayed.