troubleshooting Question

Binding List<string> to Combobox

Avatar of Xrth
Xrth asked on
Microsoft DevelopmentC#
3 Comments1 Solution8706 ViewsLast Modified:
I want to bind a List to a combobox. But somehow its not working.
If i assigne the data to the combobox its showing up, but if i change the datasource later, its not updating. So basically the binding is ot working.
I dont know if it is importent or not but the class is a singleton.
// Here is the Class
 
public class Items : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    static Items instance = null;
    static readonly object padlock = new object();
 
    Items()
    {
    }
 
    public static Items Instance
    {
        get
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new Items();
                }
                return instance;
            }
        }
    }
 
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this,
                new PropertyChangedEventArgs(propertyName));
        }
 
    }
 
    public List<string> _ItemList = new List<string>();
    public List<string> ItemList 
    {            
        get
        {
            return _ItemList;                
        }
 
        set
        {
            _ItemList = value;
            NotifyPropertyChanged("items");
        }
    }
}
 
//Here is the xaml code of the combobox
<ComboBox ItemsSource="{Binding  ItemList, Mode=OneWay}" 
 
// This is a function of the c# file from the UC where i want to bind the data
 
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            if (items.ItemList.Count <= 0)
            {
                con.sendData("LoadItems");
            }
            ddItems.DataContext = Classes.Singleton.Items.Instance;
        }
ASKER CERTIFIED SOLUTION
Xrth

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros