Reputation: 1673
I am developing application where I am processing images. Image processing take sometime (for about 10 seconds). I want to add a progress bar to complete unless image processing in done. I have this progress bar in xaml
<ProgressBar Width="200"
Foreground="#FF8B64C3"
Value="20"
Maximum="100"
BorderBrush="#FF411F72"
BorderThickness="1"/>
This is the event that is called when button is clicked for image processing
private void ProcessImageButton_Click(object sender, RoutedEventArgs e)
{
applyFilters(image1Pixels, image1Width, image1Height);
}
I want to start progress bar when this ProcessImageButton button is clicked. This is the applyFilters method.
private async void applyFilters(byte[] pixels, uint width, uint height)
{
ProcessImage processImage = new ProcessImage(pixels, width, height);
byte[] effect = processImage.applyEffect(width, height);
WriteableBitmap result_image = new WriteableBitmap((int)width, (int)height);
using (Stream stream = result_image .PixelBuffer.AsStream())
{
await stream.WriteAsync(effect, 0, effect.Length);
MainImage.Source = result_image ;
}
}
I want my progress bar to complete before storing result_image into MainImage.Source.
Upvotes: 1
Views: 3321
Reputation: 642
you can use a indeterminate progress bar
<ProgressBar x:Name="ImageProgressBar" Visibility="Collapsed" IsIndeterminate="true"/>
and you need to change the visibility before and after the image is loaded
ImageProgressBar.Visibility = Visibility.Visible;
ImageProgressBar.Visibility = Visibility.Collapsed;
Upvotes: 2
Reputation: 3582
You can use a <ProgressRing x:Name="progress" Height="50" Width="50" IsActive="False" />
and set progress.IsActive = true;
in the beginning of the operation and
progress.IsActive = false;
at the end of the operation
Upvotes: 1