【问题标题】:telerik Busy Indicator is not visibleTelerik 忙碌指示灯不可见
【发布时间】:2012-01-20 12:35:45
【问题描述】:

您好,我正在尝试将 Telerik Busy 指示器与 MVVM 一起使用。我在主窗口中有忙碌指示器。当窗口中的用户控件之一发生操作(按钮单击)时,用户控件视图模型会向 MinwindowviewModel 发送消息。在消息上,应该显示忙指示符。但这不起作用。为什么这不起作用?

用户控制视图模型

public class GetCustomerVM : ViewModelBase
{
    private int _CustomerId;
    public int CustomerId
    {
        get { return _CustomerId; }
        set
        {
            if (value != _CustomerId)
            {
                _CustomerId = value;
                RaisePropertyChanged("CustomerId");
            }
        }
    }

    public RelayCommand StartFetching { get; private set; }
    public GetCustomerVM()
    {
        StartFetching = new RelayCommand(OnStart);
    }

    private void OnStart()
    {
        Messenger.Default.Send(new Start());
        AccountDetails a = AccountRepository.GetAccountDetailsByID(CustomerId);
        Messenger.Default.Send(new Complete());
    }
}

用户控制视图模型是:

    private bool _IsBusy;
    public bool IsBusy
    {
        get { return _IsBusy; }
        set
        {
            if (value != _IsBusy)
            {
                _IsBusy = value;
                RaisePropertyChanged("IsBusy");
            }
        }
    }
    public WRunEngineVM()
    {
        RegisterForMessages();
    }

    private void RegisterForMessages()
    {
        Messenger.Default.Register<Start>(this, OnStart);
        Messenger.Default.Register<Complete>(this, OnComplete);
    }

    private void OnComplete(Complete obj)
    {
        IsBusy = false;
    }

    private void OnStart(Start obj)
    {
        IsBusy = true;
    }

在主窗口视图中,根元素是

<telerik:RadBusyIndicator IsBusy="{Binding IsBusy}" telerik:StyleManager.Theme="Windows7">

【问题讨论】:

    标签: wpf data-binding mvvm mvvm-light mvvm-toolkit


    【解决方案1】:

    AccountDetails a = AccountRepository.GetAccountDetailsByID(CustomerId); 是做什么的?我的猜测是,无论发生什么都在 UI 线程上运行。因为这一切都发生在 UI 线程上,所以 UI 永远没有机会刷新并显示 RadBusyIndicator。尝试将OnStart 中的所有工作转移到BackgroundWorker,包括发送消息。您将在此处遇到问题,因为消息将从后台线程更新 UI 线程,因此您需要使用DispatcherIsBusy 设置为truefalse

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-28
      • 2017-04-08
      • 2011-09-24
      • 2013-06-25
      • 1970-01-01
      • 2017-05-25
      • 2018-11-04
      • 1970-01-01
      相关资源
      最近更新 更多