不知道为什么会有这样的发现。我已经尝试了我能找到的所有东西,但我仍然没有让我的组合框显示该项目。
到目前为止,它显示了群组标题,但内部没有任何内容。一旦我点击下拉列表,它就会在代码中填充我的observableCollection,创建视图并将其绑定到itemsource。
另外,当我点击它时,默认项目成为第一个我能看得很清楚的项目。但是,列表仍然是空的。如果我点击它旁边并点击键盘箭头(左右),它会滚动浏览项目,所以一切都清晰存在但只是没有显示。
我很感激任何帮助。我有一种感觉,这将是一个愚蠢的事情。 :)
这是我的XAML:
<ComboBox x:Name="ExportDropDown"
DropDownOpened="GetAllProcessesAndObjects"
IsSynchronizedWithCurrentItem="True">
<ComboBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" Foreground="White" Padding="3"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding POI_processName}" Foreground="White"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
VB.NET
Sub GetAllProcessesAndObjects()
Try
Dim conn As New SqlConnection
Dim DatabaseName As String = "ImageRecognition"
conn.ConnectionString = String.Format("Data Source={0};Initial Catalog={1};User Id={2};Password={3}", General_VM.DB_DBdataSource, DatabaseName, General_VM.DB_DBusername, General_VM.DB_DBpassword)
Dim Query As New SqlCommand(
String.Format("SELECT [processid]
,[ProcessType]
,[name]
FROM [Development].[dbo].[BPAProcess];"),
conn)
Dim sda As New SqlDataAdapter(Query)
conn.Open()
Dim dt As New DataTable
sda.Fill(dt)
Dim opList As New ObservableCollection(Of ProcessObjectItem)
For Each row As DataRow In dt.Rows
Dim newItem As New ProcessObjectItem
newItem.POI_uid = row("processid")
newItem.POI_processType = row("ProcessType")
newItem.POI_processName = row("name")
opList.Add(newItem)
Next
CR_VM.CR_processCollection = opList
Dim processView As ICollectionView = CollectionViewSource.GetDefaultView(CR_VM.CR_processCollection)
If processView IsNot Nothing And processView.CanGroup = True Then
processView.GroupDescriptions.Clear()
processView.GroupDescriptions.Add(New PropertyGroupDescription("POI_processType"))
End If
processView.Refresh()
ExportDropDown.ItemsSource = processView
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
在我的viewModel(即CR_VM)中,Collection:
Private processCollection As ObservableCollection(Of ProcessObjectItem) = New ObservableCollection(Of ProcessObjectItem)
Public Property CR_processCollection() As ObservableCollection(Of ProcessObjectItem)
Get
Return processCollection
End Get
Set(ByVal value As ObservableCollection(Of ProcessObjectItem))
processCollection = value
NotifyPropertyChanged("CR_processCollection")
End Set
End Property