I recently spent a couple hours trying desperately to bind a TextBlock to the Canvas.Left and Canvas.Top properties for a project I’m working on. My binding looked like this:
{Binding ElementName=MyElement, Path=Canvas.Left, Mode=Default}
Couldn’t do it. I tried bloody everything to get this thing to work, but it wouldn’t do it.
Then I found a post on binding to attached properties (I’ve removed the link since it now points to an attack site. Thank you, Graham), which is apparently what you call a property that is written as
<TextBlock Canvas.Left=”100”
Canvas.Top=”100”
Grid.Column=”1”
Grid.Row=”1”
Grid.ColumnSpan=”1”
Grid.RowSpan=”1” />
Forgive the redundancy… I’m trying to write this post so that anyone who is having this problem can find the solution.
So the correct binding (the one that works for me, anyway) is:
{Binding (Canvas.Left), ElementName=MyElement}
It works.
Why? I have no idea.
Just passing it along.