チェックボックス付きのリストを表示するコンボ ボックスがありますが、1 日のうちに使用可能なオプションが増加することを除いて、正常に動作します。つまり、アイテムをデータバインド リストに追加します。
<ComboBox x:Name="cb" ItemsSource="{Binding Path=ActiveCommodities}"
IsEditable="True"
IsReadOnly="True"
HorizontalAlignment="Left"
Text="Commodity Filter">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding Text}"
Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
ソートされたリストの値のコレクションを公開するプロパティにバインドしています
Public ReadOnly Property ActiveCommodities As IList(Of SelectableItem)
Get
If Not _activeCommodities Is Nothing Then
Return _activeCommodities.Values
End If
Return Nothing
End Get
End Property
get にブレークポイントを設定すると、Values のアイテム数が正しいことがわかりますが、値が上がるとコンボボックスに新しいアイテムが表示されません。
私の選択したアイテムのリストは次のようになります
Public Class SelectableItemList
Inherits SortedList(Of String, SelectableItem)
Implements INotifyCollectionChanged
Protected Sub RaiseCollectionChanged(action As NotifyCollectionChangedAction)
RaiseEvent CollectionChanged(Me, New NotifyCollectionChangedEventArgs(action))
End Sub
Public Event CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) Implements System.Collections.Specialized.INotifyCollectionChanged.CollectionChanged
Public Overloads Function Add(index As String, text As String) As Boolean
If Not ContainsKey(index) Then
Dim si As New SelectableItem(text, Me)
Add(index, si)
AddHandler si.PropertyChanged, AddressOf OnSelectionChanged
RaiseCollectionChanged(NotifyCollectionChangedAction.Reset)
Return True
End If
Return False
End Function
End Class
問題は、値のコレクションにバインドしているためだと思いますか? しかし、sortedcollection にバインドしてデータ テンプレートを機能させる方法がわかりません。