Events
The ProgressBar for Xamarin exposes the following events:
-
ProgressChanged
event is raised when progress is changed. TheProgressChanged
event handler receives two parameters:- A
ProgressChangedEventArgs
which has aProgress
(double
) property. Using this property you can get the current progress of the ProgressBar control.
- A
ProgressCompleted
event is raised when the Value of the ProgressBar reaches theMaximum
value.
Example with ProgressChanged and ProgressCompleted events
The snippet below shows a simple RadLinearProgressBar
definition:
<StackLayout Margin="20"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Spacing="20">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Value, Source={x:Reference progressBar}}"
VerticalTextAlignment="Center"/>
<Stepper Minimum="0"
Maximum="180"
Increment="20"
Value="{Binding Value, Source={x:Reference progressBar}}"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="Events: "/>
<Label x:Name="statusLabel"/>
</StackLayout>
<telerikPrimitives:RadLinearProgressBar x:Name="progressBar"
Minimum="0"
Maximum="180"
Value="20"
ProgressChanged="OnProgressChanged"
ProgressCompleted="OnProgressCompleted"/>
</StackLayout>
In addition to this, you need to add the following namespace:
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
ProgressChanged
event in code behind. The Label text is updated with the current Progress
value:
private void OnProgressChanged(object sender, Telerik.XamarinForms.Primitives.ProgressBar.ProgressChangedEventArgs e)
{
this.statusLabel.Text = e.Progress.ToString();
}
ProgressCompleted
event in code behind. The Label text is updated with Text = "Completed"
when the progress reaches the Maximum
value:
private void OnProgressCompleted(object sender, EventArgs e)
{
this.statusLabel.Text = "Completed";
}
The final result when using the ProgressChanged
and ProgressCompleted
events:
A sample Events example can be found in the ProgressBar/Events folder of the SDK Samples Browser application.