Search code examples
wpfvb.netwpftoolkit

How to get list of checked items from WPF Toolkit's CheckComboBox


I cant get how to do such simple thing as getting list of all checked items from WPF Toolkit's CheckComboBox.

View:

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

View model:

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  

The main problem is that in setter of SelectedRouteSheetRecordOperations property, Value is ALWAYS Nothing (null).


Solution

  • Remove Mode=OneWayToSource from the Binding:

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

    Also note that the setter of the SelectedRouteSheetRecordOperations property is not supposed to get hit when you select an item in the CheckComboBox. An item is supposed to be added to the source collection so you might as well remove the setter and you probably want to return an ObservableCollection(Of RouteSheetRecordOperation).

    Also note that the property must be public.

    Try this along with the above XAML markup:

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