我正在尝试在某些工作中显示progessbar,但可见性不会改变......
private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
progressBar.Visibility = System.Windows.Visibility.Visible;
DoWork();//quite long (4-5 seconds)
progressBar.Visibility = System.Windows.Visibility.Collapsed;
}
是否有resfreh方法或类似的东西?我做错了吗?
答案 0 :(得分:2)
您正在UI线程中执行DoWork()
,将其阻止4到5秒。这就是您无法看到进度条的原因。
考虑在单独的线程中调用DoWork:
private async void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
{
progressBar.Visibility = System.Windows.Visibility.Visible;
await Task.Run(()=> DoWork()); //quite long (4-5 seconds)
progressBar.Visibility = System.Windows.Visibility.Collapsed;
}