WPF: Binding Combobox in Code Behind to Property

Posted by Richard on Stack Overflow See other posts from Stack Overflow or by Richard
Published on 2010-03-17T10:40:27Z Indexed on 2010/03/17 10:41 UTC
Read the original article Hit count: 630

Filed under:

Hi All,

This might be something very straight forward and I really think it should work as is, but it doesn't... I have the following scenario:

var itemSource = new Binding
    Path = new PropertyPath("ItemList"),
    Mode = BindingMode.OneTime

comboBox.SetBinding(ItemsControl.ItemsSourceProperty, itemSource);

ItemList is simply:

public IList<string> ItemList
        return Enum.GetNames(typeof(OptionsEnum)).ToList();

I would have expected this to bind the list of items to the Combobox, and when I do it in XAML it works fine, but I have to do it in code behind...

Any ideas?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#