telerik Busy Indicator不可见

kat*_*e77 2 data-binding wpf mvvm mvvm-toolkit mvvm-light

嗨,我正在尝试使用带有MVVM的telerik Busy指示器.我在Mainwindow有忙碌指示器.当窗口中的某个用户控件上有操作(按钮单击)时,用户控件视图模型会向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());
    }
}
Run Code Online (Sandbox Code Playgroud)

用户控制视图模型是:

    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;
    }
Run Code Online (Sandbox Code Playgroud)

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

<telerik:RadBusyIndicator IsBusy="{Binding IsBusy}" telerik:StyleManager.Theme="Windows7">
Run Code Online (Sandbox Code Playgroud)

cad*_*ll0 5

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