katie77
katie77

Reputation: 1811

telerik Busy Indicator is not visible

Hi I am trying to use telerik Busy indicator with MVVM. I have the Busy indicator in Mainwindow. When there is an action(button click) on one of the user controls that is in the window, the user controls view model sends an message to the MinwindowviewModel. On the message the is busy indicator should show up. But this is not working. Why is this not working?

User controls view model

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());
    }
}

The User Control View model is:

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

In the Main window View, the root element is

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

Upvotes: 2

Views: 3666

Answers (1)

cadrell0
cadrell0

Reputation: 17327

What does AccountDetails a = AccountRepository.GetAccountDetailsByID(CustomerId); do? My guess is that whatever is happeneing there is running on the UI thread. Because it is all happeneing on the UI thread, there is never a chance of the UI to refresh and show the RadBusyIndicator. Try moving all of the work on in OnStart to a BackgroundWorker, including sending the messages. You will run into issues here, because the messages will be updating the UI thread from a background thread, so you will need to use the Dispatcher to set IsBusy to true or false.

Upvotes: 5

Related Questions