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

标签 c# uwp uwp-xaml

我正在开发处理图像的应用程序。图像处理需要一些时间(大约 10 秒)。我想添加一个进度条来完成,除非图像处理完成。我在 xaml 中有这个进度条

<ProgressBar Width="200"                               
Foreground="#FF8B64C3"
Value="20" 
Maximum="100" 
BorderBrush="#FF411F72" 
BorderThickness="1"/>

这是点击按钮进行图像处理时调用的事件

private void ProcessImageButton_Click(object sender, RoutedEventArgs e)
{          
    applyFilters(image1Pixels, image1Width, image1Height);          
}

我想在单击此 ProcessImageButton 按钮时启动进度条。这是 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 ;
        }
 }

我希望我的进度条在将 result_image 存储到 MainImage.Source 之前完成。

最佳答案

你可以使用不确定的进度条

<ProgressBar x:Name="ImageProgressBar" Visibility="Collapsed" IsIndeterminate="true"/>

并且你需要在图片加载前后改变可见性

        ImageProgressBar.Visibility = Visibility.Visible;

        ImageProgressBar.Visibility = Visibility.Collapsed;

关于c# - 异步方法 C# 中的 UWP 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37866452/

相关文章:

c# - 简单的正则表达式帮助

c# - 重写方法文档

c# - 我不了解 Xamarin 中 AutomationProperties 类的行为

c++ - 在 Windows 10 通用应用程序 UWP 上覆盖关闭框

xaml - 将显示效果应用于 InkToolbar [UWP]

c# - 将任何 n 位数字四舍五入为 (n-1) 个零位

c# - 无法从Android应用程序接收Windows 10 UWP中的UDP广播

c# - 如何增加后台任务的运行时间?

c# - 在运行时更改 ThemeResource 的值不会反射(reflect)在其他 View 中

xaml - 是否可以为一个元素设置两个样式模板并决定在代码隐藏中使用哪一个?