當在WPF窗口中綁定組合框時,我遇到了一個奇怪的問題。如何在等待組合框渲染時顯示waitcursor?
我正在加載一個List對象,通過它的.ItemsSource在Window Load上填充組合框,但是它不會填充。
至少,直到點擊箭頭。一旦點擊箭頭,窗口就會凍結,一分鐘左右後,會顯示4000多條記錄。
現在,列表被加載,但是,當我單擊組合框時需要一段時間才能呈現,那麼如何在呈現列表時顯示一個waitcursor?
這裏的XAML中它:
<ComboBox Grid.Column="1"
HorizontalAlignment="Stretch" Margin="3" Name="tUser" VerticalAlignment="Stretch"
DisplayMemberPath="UsersName" SelectedValuePath="UserID" SelectedValue="0"/>
和代碼隱藏的是:
Private Sub CreateTask_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Using New WaitCursor
_LA.Show()
Me.tOrder.ItemsSource = GetOrderList()
Me.tUser.ItemsSource = GetUserList()
_LA.Hide()
End Using
End Sub
Private Function GetUserList() As List(Of UserTyping)
Dim _Qry As New List(Of UserTyping)
Using db As New DataAccess
With db
.QueryType = CmdType.InlineSQL
.Query = "Select 0 As UserID, '-Select User-' As UsersName Union All Select userID As UserID, userFullName As UsersName From vwSelectUser"
Using _Results = .GetResults()
If _Results IsNot Nothing Then
If _Results IsNot Nothing Then
_Qry = (From row In _Results.Cast(Of DbDataRecord)()
Select New UserTyping() With {
.UserID = Common.IsNull(Of Long)(row, 0, 0),
.UsersName = Common.IsNull(Of String)(row, 1, String.Empty)
}).ToList()
Else
_Qry = New List(Of UserTyping)
End If
End If
End Using
End With
End Using
Return _Qry
_Qry.Clear()
End Function
Partial Public Class UserTyping
Public Property UserID As Long
Public Property UsersName As String
End Class
只需將代碼從「組合框點擊」事件移動到「表單加載」事件。您在此處提供的代碼用於將項目添加到列表中而不是組合框。 – Himal 2012-03-14 13:54:11
對不起,忘了提及這一點,除非使用多線程,否則加載應用程序還需要一段時間。 – Himal 2012-03-14 14:01:00
請重新閱讀我發佈的代碼。該組合框由填充數據的函數填充,並且在組合框單擊事件中根本沒有任何東西。 – Kevin 2012-03-14 14:09:12