更改可见性不适用于C#windows phone 8

时间:2014-03-02 15:01:59

标签: c# xaml windows-phone-8

我正在尝试在某些工作中显示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方法或类似的东西?我做错了吗?

1 个答案:

答案 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;
}

Asynchronous Programming For Windows Phone 8