I’ve an enumerable providing a variable data set of values. The values are generated while runtime from the user.
These values are bound to an ItemsSource of a ListBox
public IEnumerable<string> Items
{
get { return list; } // list is here a dummy; it does not actually exists
}
listbox.SetBinding(ListBox.ItemsSourceProperty, new Binding { Source = Items });
Now I want to add one fixed item at the beginning. But e.g. lb.Items.Add("abc"); will break runtime. Same for the insert method.
// listbox.Items.Add("abc");
// listbox.Items.Insert(0, "abc");
How do I add a fixed item at the beginning?
You could use
Concatif you’re bound to anIEnumerable<string>Equally, if it’s a
List<string>that you’re binding to – useInsertto add the fixed item at the head after you’ve built it.