如何从WPF Toolkit的CheckComboBox

时间:2017-05-26 07:29:33

标签: wpf vb.net wpftoolkit

我无法从如何获取WPF Toolkit' CheckComboBox中所有选中项目的列表这样简单的事情。

查看:

<xctk:CheckComboBox DisplayMemberPath="Name"
                    ItemsSource="{Binding RouteSheetRecordOperations, Mode=OneWay}"
                    SelectedItemsOverride="{Binding SelectedRouteSheetRecordOperations, Mode=OneWayToSource}" />  

查看型号:

Public ReadOnly Property RouteSheetRecordOperations As New ObservableCollection(Of RouteSheetRecordOperation)
Property SelectedRouteSheetRecordOperations As List(Of RouteSheetRecordOperation)
  Get
    Return _selectedRouteSheetRecordOperations
  End Get
  Set
    _selectedRouteSheetRecordOperations = Value
  End Set
End Property  

主要问题是在SelectedRouteSheetRecordOperations属性的setter中,Value始终为Nothing(null)。

1 个答案:

答案 0 :(得分:2)

Mode=OneWayToSource

中删除Binding
<xctk:CheckComboBox DisplayMemberPath="Name"
                ItemsSource="{Binding RouteSheetRecordOperations, Mode=OneWay}"
                SelectedItemsOverride="{Binding SelectedRouteSheetRecordOperations}" />

另请注意,当您在SelectedRouteSheetRecordOperations中选择项目时,CheckComboBox属性的setter不会被命中。应该将一个项目添加到源集合中,这样您也可以删除setter,并且您可能希望返回ObservableCollection(Of RouteSheetRecordOperation)

另请注意,该媒体资源必须为public

尝试使用上述XAML标记:

Private _selectedRouteSheetRecordOperations As New ObservableCollection(Of RouteSheetRecordOperation)
Public ReadOnly Property SelectedRouteSheetRecordOperations As ObservableCollection(Of RouteSheetRecordOperation)
Get
    Return _selectedRouteSheetRecordOperations
End Get
End Property