Data Binding RadListBox SelectedItems Property
Environment
Property | Value |
---|---|
Product | RadListBox for WPF |
Version | 2024.1.312 |
Description
How to data bind the SelectedItems
of RadListBox
to a collection property in the view model.
Solution
This can be done via the ListBoxSelectedItemsBehavior.SelectedItemsSource attached property.
Defining the view model
public class MainViewModel
{
public MainViewModel()
{
Items = new ObservableCollection<MyItemType>();
// populate the Items collection
SelectedItems = new ObservableCollection<MyItemType>();
}
public ObservableCollection<MyItemType> Items { get; set; }
public ObservableCollection<MyItemType> SelectedItems { get; set; }
}
Setting the SelectedItemsSource property
<telerik:RadListBox ItemsSource="{Binding Items}"
telerik:ListBoxSelectedItemsBehavior.SelectedItemsSource="{Binding SelectedItems}"
SelectionMode="Multiple" />