Monthly Archives: July 2010

[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: