Matthias Shapiro

I need fewer hobbies

Binding To Attached Properties (like Grid.Row, Grid.Column, Canvas.Left, Canvas.Top, blah.something, etc)

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.

This entry was posted in Binding, XAML and tagged , , , , , , . Bookmark the permalink.

0 Responses to Binding To Attached Properties (like Grid.Row, Grid.Column, Canvas.Left, Canvas.Top, blah.something, etc)

  1. Graham

    Brilliant! The link in this post now points to an “Attack site” and has been blacklisted by Firefox.

  2. Chris

    Thank you so much, this helped greatly with my debugging! 🙂

    Chris

  3. DavidNcl

    Thanks very much. My exact problem solved. One would think that Blend would let you do this too and then it would be easy to see the syntax.

    Once again TVM.

  4. HG

    Thank you so very much!!! Additional thanks to Google for indexing this! 😀

  5. Matt

    I hit this too!!! Spent hours and hours and hours. Finally opened up a book randomly to the exact page that talks about this. Great blog by the way. Inspires me to share some of my own tidbits.

    Matt