I don't understand why my TreeView not update using a ObservableCollection.
Main Window
public ObservableCollection<Student> listStudents { get; set; }
internal MainWindow(List<Student> list, Controller controller)
{
this.listStudents = new ObservableCollection<Student>(list);
this.controller = controller;
InitializeComponent();
this.DataContext = this;
}
XAML
<TreeView x:Name="tv_source" AllowDrop="True" Grid.Row="2" Grid.Column="1" Margin="0,5" HorizontalAlignment="Stretch" ItemsSource="{Binding ListStudents}" Background="White" BorderBrush="{x:Null}">
I add a child like this :
public void addChild(TreeViewItem _sourceItem, TreeViewItem _targetItem)
{
Dispatcher.BeginInvoke(new Action(() => ((Student)_targetItem.DataContext).Phones.Add(_sourceItem.DataContext.ToString())));
}
Student class
public class Student
{
public string Name { get; set; }
public List<string> Phones { get; set; }
}