[Silverlight] A little work-around for the BusyIndicator control’s bug


I’m really starting to use Silverlight more and more and trying to propose to my customers every-time I can. With Silverlight 4 I also think that this platform becomes quite stable and power-full, ready to move the business application to a new level.

I was also enjoying a bit more of UI developing taking advantage of the Silverlight 4 Toolkit.. but here I found a little problem. I don’t why but after opened a page I saw my CPU indicator that became crazy (close to 100%). I started to debug a bit, I used Fiddler to see if I made some mistake in the communication between the client and the back-end server, but nothing.

After some tries, I found what was the problem: a little bug on the BusyIndicator control. I removed it and all the things went right. But I liked it and I found it useful inside my application so I decided to make a little workaround founding that the actual problem is not on the control itself but in the ProgressBar control animatiom: also after switching off the animation it looks like is not enough and the only way to let the animation leave the CPU is to disabled it.

My little work around is a simple child window with a progressbar inside like this XAML snippet:

<controls:ChildWindow x:Class="…"
            …    
<Grid x:Name="LayoutRoot" Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ProgressBar Grid.Row="0" Name="progressBar1" Height="30"/>
    </Grid>
</controls:ChildWindow>
and this is the C# code behind where I disabled the animation to avoid the CPU’s overload
    public partial class BusyChildWindow : ChildWindow
    {
        public BusyChildWindow()
        {
            InitializeComponent();
            this.progressBar1.IsIndeterminate = true;  // activate the animation...
            this.Close();
        }

        private void ChildWindow_Closed(object sender, EventArgs e)
        {
            this.progressBar1.IsIndeterminate = false;
            this.progressBar1.IsEnabled = false;
        }
    }
}

 

And that’s it…

Technorati Tags:

About palutz

Ex-MSFT SDE. Still a freak geek curious about everything. Trying to keep my mind open and to run my own start-up: http://pastesoft.com View all posts by palutz

3 responses to “[Silverlight] A little work-around for the BusyIndicator control’s bug

  • Graeme

    I was having the same problem as you where the ProgressBar was not stopping animation. I felt that there was a simple solution. I looked further on the internet and found nothing. So I played around in Blend for a while and found how to fix the problem:

    Setting the IsIndeterminate in the BusyStatusStates VisualStateGroup. Here’s the new Visual States:

    True

    False

    False

    True

    Problem Solved!

    • Graeme

      Didn’t post as expected… So

      Add “ObjectAnimationUsingKeyFrames” with Storyboard.TargetProperty=”(ProgressBar.IsIndeterminate)” Storyboard.TargetName=”progressBar” in VisualState x:Name=”Idle” & Set Value = True

      and

      Add “ObjectAnimationUsingKeyFrames” with Storyboard.TargetProperty=”(ProgressBar.IsIndeterminate)” Storyboard.TargetName=”progressBar” in VisualState x:Name=”Busy” & Set Value = False

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: