在 Caliburn.Micro 中显示来自 WPF.ExtendedToolkit 的 BusyIndi​​cator

发布于 2024-10-17 12:31:26 字数 2120 浏览 1 评论 0原文

您好,我尝试在 shell 中显示繁忙指示器,即 wpf 窗口。

在外壳视图中,我有这个:

<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>

外壳模型类在这里:

[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);

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜吻♂芭芘 2024-10-24 12:31:26

我发布我的解决方案,也许有人会有更好的主意。问题是长时间运行的任务使 UI 线程繁忙,因此我在另一个线程中的活动新视图上调用此任务和 shell 方法。

像这样:

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

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

可以显示此解锁 UI 线程和 BusyIndi​​cator。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文