I have a ListBox, I populate it with ItemsSource with List.
But when I delete or add new control for this List, I need every tim
In your Xaml, use something like this...
And wire it up like this...
public class ViewModel:INotifyPropertyChanged
{
public ObservableCollection MyItemsSource { get; set; }
public ViewModel()
{
MyItemsSource = new ObservableCollection {new ListBox(), new TextBox()};
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
This will present the items to the ListBox. In the example here, the collection contains a ListBox and a TextBox. You can add/delete from the collection and get the behaviour you are after. Controls themselves are not all that great as ListBox items because they do not have a meaningful way of populating a visual. So you will probably need to run them through an IValueConverter.