0
我想在我的StatusBar中設置TextBlock的文本,然後讓用戶等待一小段時間,而我的程序做了一些工作。有沒有簡單的方法來設置WPF StatusBar文本?
Aparently,而不是做這樣一個可愛的小功能(不工作):
Function Load(ByVal Id As Guid) As Thing
Cursor = Cursors.Wait
TextBlockStatus.Text = "Loading..."
TextBlockStatus.UpdateLayout()
Dim Found = From t In db.Thing _
Where t.Id = Id _
Select t
TextBlockStatus.Text = String.Empty
Cursor = Cursors.Arrow
Return Found
End Function
我不得不改用這個畸形:
Private WithEvents LoadWorker As BackgroundWorker
Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
InitializeLoadWorker()
End Sub
Private Sub InitializeLoadWorker()
LoadWorker = New BackgroundWorker
LoadWorker.WorkerSupportsCancellation = False
LoadWorker.WorkerReportsProgress = False
AddHandler LoadWorker.DoWork, AddressOf LoadBackgroundWorker_DoWork
AddHandler LoadWorker.RunWorkerCompleted, AddressOf LoadBackgroundWorker_RunWorkerCompleted
End Sub
Sub Load(ByVal Id As Guid)
Cursor = Cursors.Wait
LoadWorker.RunWorkerAsync(Argument)
End Sub
Private Sub LoadBackgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim Worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
Dim Id As Guid = DirectCast(e.Argument, Guid)
e.Result = From t In db.Thing _
Where t.Id = Id _
Select t
End Sub
Private Sub LoadBackgroundWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
TextBlockStatus.Text = String.Empty
Cursor = Cursors.Arrow
Dim Found As Thing = DirectCast(e.Result, Thing)
'now do something with the found thing here instead of where Load() is called.'
End Sub
和負載()函數現在是一個小組!
必須有更好的方法來處理這種簡單的情況。這不需要是異步的。
爲什麼不工作? – 2009-04-23 21:45:40
文字不更新。 – 2009-04-23 22:02:06