【问题标题】:WPF Toolkit BusyIndicatorWPF 工具包 BusyIndi​​cator
【发布时间】:2016-08-26 16:48:34
【问题描述】:

我在尝试更新 UI 时遇到问题。我需要的是,在显示BusyIndicator 后,需要更改消息,完成5 秒后,显示另一条消息两秒钟,然后隐藏BusyIndicator。谢谢!

XAML

<xctk:BusyIndicator IsBusy="{Binding IsBusy}" DisplayAfter="0">
    <xctk:BusyIndicator.BusyContentTemplate>
        <DataTemplate>
            <StackPanel>
                <mahApps:ProgressRing IsActive="{Binding IsBusy}"/>
                <Label Content="{Binding ShowMessage}"/>
            </StackPanel>
        </DataTemplate>
    </xctk:BusyIndicator.BusyContentTemplate>

    ...

</xctk:BusyIndicator>

XAML 视图模型

public string ShowMessage
{
    get { return _showMessage; }
    set
    {
        _showMessage = value;
        RaisePropertyChanged("ShowMessage");
    }
}

private void Save()
{
    ShowMessage = "Wait please...";

    Task.Factory.StartNew(() =>
    {
        IsBusy = true; // Show busyindicator and ProgressRing

        Thread.Sleep(5000); // 5 seconds to see the animation (Here is a SQL insert)

        /// Hide ProgressRing only

        ShowMessage = "Save complete.";

        Thread.Sleep(2000); // 2 seconds to see "ShowMessage"

    }).ContinueWith(x =>
    {
        IsBusy = false; // hide busyindicator and ProgressRing

        ...

    }, TaskScheduler.FromCurrentSynchronizationContext());
}

【问题讨论】:

    标签: c# wpf .net-4.0 wpftoolkit


    【解决方案1】:

    有点晚了,但是 ShowMessage = "保存完成。";未在 UI 线程上运行。 RaisePropertyChanged 必须正常工作,因此您需要插入另一个 Continuation 和 Task 以使用 FromCurrentSynchronizationContext 执行 ShowMessage。

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2016-07-13
      • 2011-09-17
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 2016-03-22
      • 2013-05-19
      • 1970-01-01
      相关资源
      最近更新 更多