2017-05-26 48 views
2

我無法得到如何做這樣簡單的事情,比如從WPF Toolkit的CheckComboBox中獲取所有選中項目的列表。如何從WPF工具包的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財產的二傳手,值始終沒有(空)。

+0

你看看這個? https://stackoverflow.com/questions/19798451/wpf-toolkit-checklistbox-selecteditemsoverride-not-working – Snicker

回答

2

Binding刪除Mode=OneWayToSource

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

還要注意的是SelectedRouteSheetRecordOperations setter方法是不應該當您選擇在CheckComboBox一個項目遭到襲擊。一個項目應該被添加到源集合,所以你可能會刪除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 
相關問題