Articles in this section
Category / Section

How to load ListBox as drop-down content of WPF DropDownButtonAdv?

1 min read

This article explains how to load a ListBox as the content to the WPF DropDownButtonAdv. ListBox control can be loaded as dropdown content by setting DropDownButtonAdv.Content property. ListBox SelectedItem bound to ViewModel to listen selection changes and execute 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.
        }
 
    }

 

DropDownButtonAdv

 

Sample: View sample in GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied