How to Load ListBox as Drop-down Content of WPF DropDownButton?
This article explains how to load a ListBox as the content for the WPF DropDownButtonAdv. The ListBox control can be loaded as dropdown content by setting the DropDownButtonAdv.Content property. The ListBox SelectedItem bound to ViewModel to listen for selection changes and execute the appropriate action.
XAML
<syncfusion:DropDownButtonAdv Label="{Binding SelectedItem}"> <ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> </syncfusion:DropDownButtonAdv>
ViewModel
public class ViewModel : INotifyPropertyChanged { public ViewModel() { items = new ObservableCollection<string>(); items.Add("Item1"); items.Add("Item2"); items.Add("Item3"); items.Add("Item4"); items.Add("Item5"); items.Add("Item6"); items.Add("Item7"); items.Add("Item8"); } private ObservableCollection<String> items; public ObservableCollection<String> Items { get { return items; } set { items = value; } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string property) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(property)); } private string selectedItem = "Item1"; public string SelectedItem { get { return selectedItem; } set { selectedItem = value; OnPropertyChanged("SelectedItem"); OnSelectedChanged(value); } } private void OnSelectedChanged(string SelectedItem) { //Gets called when selection changed in ListBox. } }
Sample: View sample in GitHub
Conclusion
I hope you enjoyed learning about how to load ListBox as drop-down content of WPF DropDownButton.
You can refer to our WPF DropDownButton featuretour page to know about its other groundbreaking feature representations and documentation, to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!