简体   繁体   English

异步方法C#中的UWP进度条

[英]UWP Progress Bar in Async method C#

I am developing application where I am processing images. 我正在开发我正在处理图像的应用程序。 Image processing take sometime (for about 10 seconds). 图像处理需要一段时间(大约10秒钟)。 I want to add a progress bar to complete unless image processing in done. 我想添加一个进度条来完成,除非图像处理完成。 I have this progress bar in xaml 我在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. 我想在单击此ProcessImageButton按钮时启动进度条。 This is the applyFilters method. 这是applyFilters方法。

 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. 我希望在将result_image存储到MainImage.Source之前完成进度条。

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;

You can use a <ProgressRing x:Name="progress" Height="50" Width="50" IsActive="False" /> 您可以使用<ProgressRing x:Name="progress" Height="50" Width="50" IsActive="False" />

and set progress.IsActive = true; 并设置progress.IsActive = true; in the beginning of the operation and 在操作的开始和

progress.IsActive = false;

at the end of the operation 在操作结束时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM