Oh now I know what mistake you did.
You are setting the
ItemsSource
everytime you click it and you have used a List which can replaced with
ObservableCollection
which can notify you when your collection changed.
In the way that I am going to explain below, you don't have to set the
ItemsSource
again and again.
It can be solved in this way:
public partial class Window1 : Window
{
private ObservableCollection<tripinfo> trips;
public Window1()
{
InitializeComponent();
this.Loaded+=new RoutedEventHandler(Window1_Loaded);
}
public Window1_Loaded(object sender,RoutedEventArgs e)
{
trips=new ObservableCollection<tripinfo>();
trips.Add(new TripInfo(false,"Delhi"));
trips.Add(new TripInfo(true,"New York"));
list.ItemsSource=trips;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
trips.Add(new TripInfo(false, textBox1.Text));
}
}</tripinfo></tripinfo>
Hope it helped! :)