How can I change progress bar value in BusyIndicator?

May 19, 2011 at 1:43 PM

I'm using default template. How can i change value of displayed progress bar?

May 19, 2011 at 1:46 PM

This behavior is not supported by default.  What you could do it use your own BusyContentTemplate.

May 19, 2011 at 1:52 PM

Actually, now that I think about it, you may be able to accomplish this by creating a style and data triggers then setting the BusyIndicator.ProgressBarStyle property.

May 19, 2011 at 2:34 PM

WPF is awesome :-)

 

<extToolkit:BusyIndicator IsBusy="True" BusyContent="{Binding BusyText}" >
	<extToolkit:BusyIndicator.ProgressBarStyle>
		<Style TargetType="ProgressBar">
			<Setter Property="IsIndeterminate" Value="False"/>
			<Setter Property="Height" Value="15"/>
			<Setter Property="Margin" Value="8,0,8,8"/>
			<Setter Property="Value" Value="{Binding ProgressValue}"/>
		</Style>
	</extToolkit:BusyIndicator.ProgressBarStyle>
</extToolkit:BusyIndicator>

This works like a charm :-)

Jul 8, 2011 at 4:35 PM
Edited Jul 8, 2011 at 5:44 PM
Granted I'm a newb when it comes to WPF, but there's a few things that I just can't figure out in relation to BusyIndicator:

  1. Why doesn't the binding within the <DataTemplate> work, yet if the binding is in the <ProgressBarStyle> it does but shows up below the buttons?
  2. Why doesn't the <ProgressBarStyle> apply it's settings/values to the <ProgressBar> in <DataTemplate>?

I started with an exact copy of the example in the Documentation page for BusyIndicator - Custom Content, but couldn't figure out why the ProgressBar wasn't updating despite the value updating in the background. If I "un-collapsed" the <ProgressBarStyle> I could then see that instance of <ProgressBar> updating, but it was below the <StackPanel>. What I'm actually trying to accomplish is a very detailed BusyIndicator window with two <ProgressBar>'s tied to two different values. In the meantime I've just removed the <DataTemplate> and stuffed everything (except the bar) into the BusyContent string/binding and set a click event on the control itself to allow user interaction (i.e. Cancel/Continue) since the buttons are only available in the <DataTemplate>. All the bindings work fine outside of the <DataTemplate>.

Confused...any ideas on what I'm doing wrong?

<extToolkit:BusyIndicator Name="busy" IsBusy="{Binding ShowBusy}" DisplayAfter="0" MouseLeftButtonDown="busy_MouseLeftButtonDown">
        <extToolkit:BusyIndicator.BusyContentTemplate>
            <DataTemplate>
                <StackPanel Margin="4">
                    <TextBlock Text="Processing ..." FontWeight="Bold" HorizontalAlignment="Center"/>
                    <StackPanel Margin="4">
                        <TextBlock Text="{Binding BusyContent}"/>
                        <ProgressBar Value="{Binding ProgressFileValue}" Maximum="{Binding ProgressFileMax}" Height="15" Margin="0,4,0,4" IsIndeterminate="False" />
                    </StackPanel>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/>
                        <Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </extToolkit:BusyIndicator.BusyContentTemplate>
        <extToolkit:BusyIndicator.ProgressBarStyle>
            <Style TargetType="ProgressBar" >
                <Setter Property="Visibility" Value="Visible" />
                <Setter Property="Height" Value="15"/>
                <Setter Property="Margin" Value="14,0,14,14"/>
            </Style>
        </extToolkit:BusyIndicator.ProgressBarStyle>
Jul 8, 2011 at 10:44 PM

Be sure that you aren't trying to update the UI from a background thread, because you can't.  You need to take the value and propagate it to the UI thread which can be done a number of ways.  Here is a post that may help.

http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/

Jul 11, 2011 at 1:22 PM
Edited Jul 11, 2011 at 2:40 PM

I'm updating a class level int (ProgressValue) during the ProgressChanged event of my background worker.  Works fine on the ProgressBarStyle, but not within the DataTemplate.

Here's a good example...both ProgressBar instances reference the same bindings, but result in different behavior.  I'm sure it's just something stupid I'm doing wrong, but it's baffling to say the least...

XAML:

    <extToolkit:BusyIndicator Name="busy" IsBusy="{Binding ShowBusy}" BusyContent="{Binding BusyContent}"  DisplayAfter="0" MouseLeftButtonDown="busy_MouseLeftButtonDown">
        <extToolkit:BusyIndicator.BusyContentTemplate>
            <DataTemplate>
                <StackPanel Margin="4">
                    <TextBlock Text="Processing ..." FontWeight="Bold" HorizontalAlignment="Center"/>
                    <StackPanel Margin="4">
                        <TextBlock Text="{Binding Path=BusyContent}"/>
                        <ProgressBar Value="{Binding ProgressFileValue}" Maximum="{Binding ProgressFileMax}" Height="15" Margin="0,4,0,4" IsIndeterminate="False" />
                    </StackPanel>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/>
                        <Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </extToolkit:BusyIndicator.BusyContentTemplate>
        <extToolkit:BusyIndicator.ProgressBarStyle>
            <Style TargetType="ProgressBar" >
                <Setter Property="Visibility" Value="Visible" />
                <Setter Property="IsIndeterminate" Value="False"/>
                <Setter Property="Height" Value="15"/>
                <Setter Property="Margin" Value="14,0,14,14"/>
                <Setter Property="Value" Value="{Binding ProgressFileValue}"/>
                <Setter Property="Maximum" Value="{Binding ProgressFileMax}"/>
            </Style>
        </extToolkit:BusyIndicator.ProgressBarStyle>

Result:

http://commondatastorage.googleapis.com/irevolve-shared/busyIndicator.PNG

Jul 12, 2011 at 1:33 PM

Do you have a sample application you can share?

Jul 12, 2011 at 2:02 PM

I'll see about putting one together.  Thanks Brian...

Mar 6, 2012 at 2:28 PM

I would like display BusyIndicator and I want define a value et change the text in caption...

I try with Dispatcher and BackgroundWorker, but no work !!!!

Have you a sample projet in VB.Net 2010 ?

Thank you

 

 

 

Aug 5, 2013 at 2:15 PM
Edited Aug 5, 2013 at 2:34 PM
After looking around and trying a few things, I finally found the solution here:

http://stackoverflow.com/questions/12515710/problems-with-binding-data-to-data-templates-inside-a-busyindicator

When binding, use RelativeSource and then refer to its DataContext and the appropriate property. In my case (I am using Caliburn.Micro and had to search for UserControl, not Window when searching for the Ancestor):
<ProgressBar Value="{Binding Path=DataContext.TaskProgress, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
(Although it is an old thread, I decided to put the info here because google returns this page as the first one in the search I used... Hopefully it helps others...)