1

嗨,我尝试在 wpf 窗口的 shell 中显示忙碌指示器。

在 shell 视图中,我有这个:

<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模型类在这里:

[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()
    {

    }
}

我从活动视图模型类运行应用程序,我称之为:

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

            //...

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

            //long task

            Shell.Show2(logOnResult.ReturnValue);

问题是在另一个视图处于活动状态时会显示忙碌指示符。

4

1 回答 1

1

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.

于 2011-02-11T21:27:10.170 回答