none
How can I bind a value to the Canvas.Top property?

    Question

  • I've tried the following but it is not working:

     

    Binding binding = new Binding();

    binding.Source = element;

    binding.Path = new PropertyPath("Canvas.TopProperty");

    line.SetBinding(Line.X1Property, binding);

     

     

    How can I get it to work?

    Tuesday, May 13, 2008 12:35 AM

Answers

  • That original code is OK too, you just need to change the PropertyPath from

     

    new PropertyPath("Canvas.TopProperty");

     

    to

     

    new PropertyPath("(Canvas.Top)")

     

    ... The first difference is to specify the property as "Top", rather than "TopProperty", because this syntax is specifying the CLR property, not the backing DP.  The second difference is to use parens, indicating that this is an attached property.

     

    Thursday, May 15, 2008 5:20 AM

All replies

  • To get this working, the UIElement identified by "element" variable should be added into Canvas.Children collection.

    hope this helps
    Wednesday, May 14, 2008 2:56 AM
  • As Marco said your line should belong to desired canvas children collection. Also you can use direct dependency property instead of string representation. Something like

    Binding binging = new Binding();

    binging.Path = new PropertyPath(Canvas.TopProperty);

     

    Wednesday, May 14, 2008 6:42 AM
  • That original code is OK too, you just need to change the PropertyPath from

     

    new PropertyPath("Canvas.TopProperty");

     

    to

     

    new PropertyPath("(Canvas.Top)")

     

    ... The first difference is to specify the property as "Top", rather than "TopProperty", because this syntax is specifying the CLR property, not the backing DP.  The second difference is to use parens, indicating that this is an attached property.

     

    Thursday, May 15, 2008 5:20 AM