1

I am new in WPF, need to bind a line to 2 dots.

But the code bellow does not work:

<Canvas>
    <Ellipse x:Name="dot1" Width="5" Height="5" 
             Canvas.Left="50" Canvas.Top="50"/>
    <Ellipse x:Name="dot2" Width="5" Height="5" 
             Canvas.Left="100" Canvas.Top="100"/>

    <Line 
             X1="{Binding ElementName='dot1', Path='Canvas.Left'}" 
             Y1="{Binding ElementName='dot1', Path='Canvas.Top'}"

             X2="{Binding ElementName='dot2', Path='Canvas.Left'}" 
             Y2="{Binding ElementName='dot2', Path='Canvas.Top'}"/>
</Canvas>

Where is the error? Thanks!

2 Answers 2

3

I think the error you are getting because of the single quote " ' " , i think it should be like this

<Line 
         X1="{Binding ElementName=dot1, Path=Canvas.Left}" 
         Y1="{Binding ElementName=dot1, Path=Canvas.Top}"

         X2="{Binding ElementName=dot2, Path=Canvas.Left}" 
         Y2="{Binding ElementName=dot2, Path=Canvas.Top}"/>

if it didnt work try this alternative syntax , just a work around : EX:

< TextBox Name="TextBox1">
    < TextBox.Text>
        < Binding ElementName="Slider1" Path="Value" />
    < /TextBox.Text>
< /TextBox>

take a look at this : http://www.wpfdude.com/articles/BindingToElement.aspx

Sign up to request clarification or add additional context in comments.

Comments

1
<Line  Stroke="Black" StrokeThickness="1" 
       X1="{Binding ElementName=dot1, Path=(Canvas.Left)}" 
       Y1="{Binding ElementName=dot1, Path=(Canvas.Top)}"

       X2="{Binding ElementName=dot2, Path=(Canvas.Left)}" 
       Y2="{Binding ElementName=dot2, Path=(Canvas.Top)}"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.