开发者

How to show Silverlight Toolkit Busy Indicator during calculation?

开发者 https://www.devze.com 2023-03-21 06:57 出处:网络
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 someth

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 notification开发者_JAVA百科s 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??


The busyindicator control needs

DisplayAfter="0"


I also faced the similar problem where, busy indicator was shown forever sometimes and looks like the problem is resolved by setting DisplayAfter to "0".

Step 1. Showing busy indicator and then invoking a javascript function:

BusyIndicator.IsBusy = true;
HtmlPage.Window.Invoke("foo", id);  

Step 2. Javascript function does a post back and once the post back is completed, it calls Silverlight function to close the busy indicator by setting:

BusyIndicator.IsBusy = false;

Problem: javascript function calls silverlight function to close the busy indicator before the busy indicator is really shown on the UI (though we have set IsBusy to true before invoking javascript).

Solution: I have observed that DisplayAfter value was set to 00.00.00.1 in xaml and I have changed to

BusyIndicator.DisplayAfter = TimeSpan.Zero

in code behind. This has solved my problem. But I want to check whether HtmlPage.Window.Invoke is a synchronous or asynchronous call?

Thanks for your inputs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号