Progress Bar Control and Progress Ring Control, Using Repeat Button In UWP

A Progress Control provides feedback to the user about running the ongoing operation. So, the user cannot interact with the app when the progress indicator is visible, and can also indicate the waiting time.

Types of Progress Control

There are two types of Progress controls- ProgressBar and ProgressRing.

  • The ProgressBar displays a vertical bar that shows the percentage completed of a task but its progress should not block the user's interaction with the app.

    Control

  • The ProgressRing displays like a ring. The user interaction is blocked until the operation has completed.

    Control

Prerequisites

  •    Visual Studio 2015

Now, let's get started with the following steps.

Step 1 - Create Windows Universal Project


Open Visual Studio 2015 and click File - New - Project Option for New Universal App.

Control

Step 2 - Giving the Project Name

Then, New Project window will open. There, select Installed -> Template -> Visual C# -> Windows -> Universal and select a Blank App (Universal Windows).

Type Project Name as ProgressBarApp and click the OK button.

Control

Step 3 - Setting the platform Versions

Here, we choose the Target Version and Minimum Version for our Universal Windows application. Click OK button

Control

Step 4 - Choose Designer Window

Now, go to the Solution Explorer and open the MainPage.xaml for design.

Control
 
Step 5 - Designing the App

In the MainPage.xaml designing page, drag TextBlock button control from the tool box. Then, go to the Property window and click Text then Enter the given text.

Control

Next, drag the Progress Bar button from the tool box and go to the property then change the Name as ProgressBarcontrol

Control

Now, drag the Repeat button from the tool box and goto the property then change the content as Press and Hold

Control

After designing the app, the XAML code looks like this.

Control

  1. <Page x:Class="ProgressBarAppp.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:ProgressBarAppp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">  
  2.     <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
  3.         <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Height="71" Margin="10,44,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="340">  
  4.             <Run Text="Progress Bar" />  
  5.             <Run Text=" " />  
  6.             <Run Text="Control " />  
  7.             <Run Text=" using Repeat Button Control" />  
  8.             <Run Text="in UWP" /> </TextBlock>  
  9.         <ProgressBar x:Name="ProgressBarcontrol" Value="0" Maximum="200" Margin="22,161,20,439" Height="40" />  
  10.         <RepeatButton Content="Press and hold" Click="RepeatButton_Click" Width="197" Margin="86,235,0,353" Height="52" /> </Grid>  
  11. </Page>   

Step 6 - Add the Coding

To add coding, double click on the Repeat Button, then add the mentioned source code.

Control

  1. private static int X = 0;  
  2. private void RepeatButton_Click(object sender, RoutedEventArgs e)   
  3. {  
  4.     X += 1;  
  5.     ProgressBarcontrol.Value = X;  
  6.     if (X >= ProgressBarcontrol.Maximum) X = 0;  
  7. }  
  8. }   

Step 7 - Run the Application

Now, we are ready to run our Project. So, click the Local Machine for running the Application.

Control

Output 1 

Control

Output 2

Control

Step 8 - Add the Progress Ring

Now, add the Progress Ring Control to the app.

Drag the Progress Ring button from the tool box and go to the property. Then check the IsActive checkbox,

Control

Step 9 - Run the Application

Now, we are ready to run our Project. So, click the Local Machine for running the application.



Output 3



Step 10 - Changing the colour of the Progress Ring

By default, the main coloring of the progress controls is set to the accent color of the system.

  1. <ProgressRing IsActive="True" Height="100" Width="100" Foreground="Red"/> 
Step 11 - Run the Application

Now, we are ready to run our Project. So, click the Local Machine for running the application



Output 4 



Conclusion - 
I hope you understood how to create the Progress Bar Control and Progress Ring with the uses of Repeat button, in the Universal app and how to run it.

Up Next
    Ebook Download
    View all
    Learn
    View all