I set DataContext:
this.DataContext = new MainWindowViewModel();
And I am binding the ItemsSource of a TabControl, when I add a new TabItem in the contructor of MainWindowViewModel it is working! But when I add a new TabItem in an event (Click) there is no effect.
I have this property:
List<Item> _listOfItem;
public List<Item> ListOfItem
{
get
{
return _listOfItem;
}
set
{
_listOfItem = value;
PropertyChanged(this, new PropertyChangedEventArgs("ListOfItem"));
}
}
Please help.
You should use an
ObservableCollection, rather than aListif you wish the UI to be notified of collection changes.Note that you only need to invoke the
PropertyChangedevent for yourListOfItemif the reference changes after construction of your view model type. If it doesn’t change, then a simple auto property will suffice forListOfItem.