Wednesday, February 10, 2010

Items collection must be empty before using ItemsSource.

In general, you are probably getting this message because you are trying to bind to the ItemsSource property and you have hard coded some items in your XAML. You can do one or the other, but not both.

I ran into this when I was trying to define a template for my ComboBoxItems. The thing that I forgot was to put the <ComboBox.ItemTemplate>. If you don’t put that tag first then everything is interpreted as hard coding values, even if you have databinding tags.

This stackoverflow page explains some issues and problems pretty well.

1 comment:

Tim Dunnington said...

Thanks! This is exactly the problem I had. I put the template in the wrong place and confused the list.