-2

i have ComboBox binding with my collection and now i want to add another Item before the binding: "Please select..." So i try this:

combobox.Items.Add("Please select");

But because i have this dinging:

public ObservableCollection<MyData> collection { get; set; }

ItemsSource="{Binding collection}"

All i received is this error:

Items collection must be empty before using ItemsSource

So how can i solve it ?

berry wer
  • 637
  • 2
  • 12
  • 25

1 Answers1

0

If you are binding to an ItemsSource, you cannot manually update the items in the combobox as this would invalidate the binding. If you want another value in your ItemsSource, just add it to "collection" in your ViewModel.

Xcalibur37
  • 2,305
  • 1
  • 17
  • 20