Your code is a little bit confusing because you have duplicate property names and have obviously tested a lot during "Voodoo programming". :)
However, I think I found your problem anyway. Try to remove the following line in your TimeLine
class:
this.DataContext = this;
This should not be in the control, but only in the MainWindow
.
Explanation:
In the MainWindow constructor you set the MainWindow's DataContext
to itself. Child elements inherit their DataContext
from their parent element if it is not explicitly set. Therefore, the DataContext
of the TextBlock
is also set to the MainWindow which is why the Binding
works properly here. However, in all TimeLine
instances, you set the DataContext
explicitly to themselves (in the constructor), i.e. the TimeLine
object. This way, the Binding
on the TimeLine
instance does not refer to the MainWindow
's StartTime
property, but to the property with the same name in the TimeLine
control. However, this property is never set to any real value (only bound to itself which does not make sense). Therefore, nothing is displayed.