开发者

Binding problem in WPF

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="开发者_StackOverflow中文版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!


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


<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)}"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜