Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Databinding combobox to a list<string>

I am having a difficult time trying to bind my property which is of type List to my combobox through XAML.

public List<string> MyProperty  { get; set; }

The following XAML binding does not work:

<ComboBox Name="cboDomainNames" ItemsSource="{Binding Path=MyProperty}"/> 

But the following assignment:

cboDomainNames.ItemsSource = MyProperty;

works perfectly. What i am missing here?

like image 449
ioWint Avatar asked Jul 28 '11 05:07

ioWint


1 Answers

Posting my comment back to mark the answer.

My DataContext was set, BUT it was set after InitializeComponent(). I thought that could be the problem. Then I realized that as I am binding through xaml, when the view loads, the binding happens to the property which is empty.

The property gets populated when the view is ready after its loaded (i.e on _presenter.OnViewReady()). Since it's not an observable collection nothing gets added to the combobox. Specifying it from my code behind works, because at that time the data exists in the property.

like image 60
ioWint Avatar answered Oct 11 '22 23:10

ioWint