The way to update the binding target (in your case TextBlock.Text) is to implement the INotifyPropertyChanged interface on your data object (class line) and then raise the RaisePropertyChanged event when the value of the binding source (start_time, etc.)
changes. This way WPF binding will know that data changed and it will update UI automatically.
This is an example of implementing the INotifyPropertyChanged interface:
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace WBS.DataLayerSimple
{
public class BaseObject : INotifyPropertyChanged
{
// Tracking changes
public bool IsDirty { get; set; }
// Implementation of INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
}
}
then you can inherit from ObjectBase and raise the RaisePropertyChanged event. The 'Book' class would be your 'line' class:
using System;
namespace WBS.DataLayerSimple
{
public class Book : BaseObject
{
private string title;
public string Title
{
get
{
return title;
}
set
{
if (title != value)
{
title = value;
IsDirty = true;
RaisePropertyChanged("Title");
}
}
}
private string authors;
public string Authors
{
get
{
return authors;
}
set
{
if (authors != value)
{
authors = value;
IsDirty = true;
RaisePropertyChanged("Authors");
}
}
}
private string isbn13;
public string Isbn13
{
get
{
return isbn13;
}
set
{
if (isbn13 != value)
{
isbn13 = value;
IsDirty = true;
RaisePropertyChanged("Isbn13");
}
}
}
}
}
The above code was taken from:
http://wbswiki.com/doku.php?id=notes:wpf:datalayersimple
Leszek
Wiki: wbswiki.com
Website: www.wisenheimerbrainstorm.com