Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

Have used progress bar in WPF application. Show the progress bar when before load the grid values. After load the grid progress bar set to invisible. The below code have used.

XML
<Grid>
        <ProgressBar Margin="10,10,0,13" Name="PBar" HorizontalAlignment="Left" Foreground="#FFB9C3D5" IsIndeterminate="True"
                 VerticalAlignment="Top" Width="300" Height="30" Value="20" FlowDirection="LeftToRight" ContextMenuOpening="PBar_ContextMenuOpening">
            <ProgressBar.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="PBar" Storyboard.TargetProperty="Value" From="0" To="100" Duration="0:0:0" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ProgressBar.Triggers>
        </ProgressBar>


In design page progress bar was animated. But progress bar was not animated when run the application. Only show the progress bar.

Please give me the solution.

Thanks in Advance.
Regards,
Maha
Posted
Updated 12-Jun-11 23:15pm
v2

1 solution

XML
<StatusBar Name="sbar"
           VerticalAlignment="Bottom" Background="Beige" >

  <StatusBarItem>
    <TextBlock>Downloading File</TextBlock>
  </StatusBarItem>
  <StatusBarItem>
    <ProgressBar Width="100" Height="20"
                 Name="progressBar1">
      <ProgressBar.Triggers>
        <EventTrigger RoutedEvent="ProgressBar.Loaded">
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation
                Storyboard.TargetName="progressBar1"
                Storyboard.TargetProperty="Value"
                From="0" To="100" Duration="0:0:5"  />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </ProgressBar.Triggers>
    </ProgressBar>
  </StatusBarItem>
  <Separator/>
  <StatusBarItem>
    <TextBlock>Online</TextBlock>
  </StatusBarItem>
  <StatusBarItem HorizontalAlignment="Right">
    <Image Source="images\help.bmp" Width="16" Height="16"/>
  </StatusBarItem>
</StatusBar>


C# (code behind)
ProgressBar progbar = new ProgressBar();
progbar.IsIndeterminate = false;
progbar.Orientation = Orientation.Horizontal;
progbar.Width = 150;
progbar.Height = 15;
Duration duration = new Duration(TimeSpan.FromSeconds(10));
DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration);
progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);

For more details see this link
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900