2012-04-19 50 views

回答

0

在UI线程繁忙期间无法显示加载动画,但可以使用适当的文本显示静态通知,如TextBlock控件。但是,如果在更新TextBlock控件的文本后立即在UI线程上开始长时间运行操作,则控件的UI将不会更新,直到操作结束。要解决这个问题,您可以使用以下问题的答案中描述的技巧:Showing a text indicator before freezing the Silverlight UI thread

0

首先,看看使用后台线程做长期工作。如果这是不可能的,即真正花费时间在UI线程上加载UI组件,那么您肯定可以在加载部件顶部放置一个繁忙指示器作为覆盖层,然后在加载所有内容时隐藏覆盖层。

顺便说一下,它很难编写响应式的多线程应用程序,而无需将UI逻辑与UI分离。研究'MVVM'模式。使用MVVM将使您的应用程序突飞猛进。

我想说,没有严重的应用程序使用“后面的代码”,即一切都通过DataContext,数据绑定,ViewModels和Commands完成。

否则,请查看使用任务或BackgroundWorker并理解Dispatcher。

卢克

0

尝试使用DispatcherTimer设置运行任务重调用之前(通过使用延迟)的忙闲指示。

然后,您可以在重任务完成后禁用指示器。

适合我。

'enable busy indicator & set up the timer' 
Private Sub renderControl(ByVal sender As Object, ByVal e As RoutedEventArgs) 

     _busyIndicator.IsBusy = True 

     Dim timer As New DispatcherTimer 
     timer.Interval = TimeSpan.FromMilliseconds(100) 
     AddHandler timer.Tick, AddressOf renderControl_TimerTick 
     timer.Start() 

    End Sub 

'do your heavy task, disable busy indicator then stop the timer' 
    Private Sub renderControl_TimerTick(ByVal sender As Object, ByVal e As EventArgs) 

     DoStuff() 

     _busyIndicator.IsBusy = False 

     'Stop the timer' 
     TryCast(sender, DispatcherTimer).[Stop]() 

    End Sub 

希望这有助于!

相关问题