The task: implement the simplest Dependency Property ever, which can be used in xaml like that:
The Text
property is located on the DataContext
of the MainWindow not of the UserControl.
So change this line
into this:
Which will tell the Binding that you're talking about the Text element located in you MainWindow. Of course, since in this example I used ElementName
, you're going to want to name your window MyMainWindow...
So add this to your MainWindow:
If you rather not name your window, you can use the RelativeSource FindAncestor binding like this:
In both ways, you are asking to find the property named 'Text' in the DataContext of the window.