Animated ProgressBar WPF in VB.NET

This article defines an animated progressBar in WPF and XAML.
  • 4573
Download Files:
 

This article defines an animated progressBar in WPF and XAML.

WPF ProgressBar with animation

In this article we take a Button control to start the ProgressBar and StatusBar control to display the progress With animation and a TextBlock control to add text.

The form looks like the below Figure1.

1.gif

Figure1.gif

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <StackPanel>

        <Button Content="Start" Click="MakeOne" Width="189" />

        <StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" >

            <StatusBarItem>

                <TextBlock>StatusBar</TextBlock>

            </StatusBarItem>

        </StatusBar>

    </StackPanel>

</Window>

Now double click on the Button control and add the following code.

Private Sub MakeOne(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

        sbar.Items.Clear()

        Dim lbl As New Label()

        lbl.Background = New LinearGradientBrush(Colors.Pink, Colors.Red, 90)

        lbl.Content = "Progress"

        sbar.Items.Add(lbl)

        Dim progbar As New ProgressBar()

        progbar.Background = Brushes.Gray

        progbar.Foreground = Brushes.Green

        progbar.Width = 150

        progbar.Height = 15

        Dim duration As New Duration(TimeSpan.FromMilliseconds(2000))

        Dim doubleanimation As New Animation.DoubleAnimation(100.0, duration)

        doubleanimation.RepeatBehavior = New RepeatBehavior(3)

        progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation)

        sbar.Items.Add(progbar)

    End Sub

Now run the application and click on the button start to start progress.

2.gif

Figure2.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.