Access Selected Items in CheckComboBox
See original GitHub issueI try to access to the Selected Items of the CheckComboBox. The goal is, to be able to selected Columns of a Table that you want to show. It seem like there is no way to do it in a MVVM achitecture.
The first way I was thinking is : <hc:CheckComboBox SelectedItems="{Binding MySelectedList}" />
but according to the issue #485 the SelectedItems is not a Property.
I found another way that not working but suppose to ^^. It is to create a class Item with 2 properties : Name and Selected and link them to the Property DisplayMemberPath and SelectedValuePath, see example below :
Model/Item.cs
public class Item{
public string Name { get; set; }
public bool Selected { get; set; }
}
ViewModel/MainWindowViewModel.cs
public class MainWindowViewModel{
public ObservableCollections<Item> MyItemList { get; set; } = new ObservableCollections<Item>() {
new Item() { Name = "column", Selected = true},
new Item() { Name = "column", Selected = true},
new Item() { Name = "column", Selected = false},
new Item() { Name = "column", Selected = false},
}
}
View/MainWindow.xaml
<hc:CheckComboBox Width="300" ItemsSource="{Binding MyItemList }" ShowClearButton="True"
ShowSelectAllButton="True" MaxHeight="30" DisplayMemberPath="Name" SelectedValuePath="Selected"/>
Is there a way to access to Selected Items without using the code behind (.xaml.cs) ? Is there an improvement to make in the CheckComboBox ?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Hi 🖐,
Here a little exemple how I make it work :
MainWindow.xaml.cs :
and the xaml : MainWindow.xaml :
Hope it can help !
closed in 7519c7e