Search code examples
silverlightsilverlight-toolkitbusyindicator

How to show Silverlight Toolkit Busy Indicator during calculation?


I'm having some problems implementing a control that shows a Busy indicator, here is the scenario: I have a simple View with a busy indicator and a TextBlock, this bind to a ViewModel (that is something like the following).

public class ViewModel
{
    private bool _isbusy;
    public bool IsBusy
    {
        get { return _isbusy; }
        set
        {
            _isbusy=value;
            OnPropertyChanged("IsBusy");
        }
    }

    private string _text;
    public string Text
    {
        get { return _text; }
        set
        {
            _text = value;
            OnPropertyChanged("Text");
        }
    }

    public void CallMe()
    {
        IsBusy = true;
        Text = Static.PerformCalculation();
        IsBusy = false;
    }
}

So far all pretty simple, no?? The problem is when i have a method like CallMe(). I have to show and hide the busy indicator while the calculation is being done, i thougth that the reason was that the calculations and the IsBusy property notifications where done on the same thread, so i came out with something like this:

public void CallMe()
{
    IsBusy = true;
    Static.PerformCalculationAsync(CalculationCallback);
}

private void CalculationCallback(string result)
{
    Text = result;
    IsBusy = false;
}

Now something different happen, the Busy Indicator loads fine, but when the calculation is too short the BusyIndicator isn't shown and there is a small delay between the CallMe() method called and the Text appears on the screen. This is my problem, i want that the Text property gets calculated (and shown on the screen) before the BusyIndicator gets hidden.

Does anyone know a good way to do this, or has any advice that i can follow??


Solution

  • The busyindicator control needs

    DisplayAfter="0"