开发者

Silverlight Binding properties of a UIElement to properties of another UIElement dynamically

A list of ellipses and lines are added as Children to LayoutRoot. Lines are connecting between ellipses.

How can I bind these two elements together so that when ellipse moves lines should also move?

How can I bind the X1property,X2property,Y1property,开发者_运维技巧Y2property to center of ellipses?


  1. Assume that the parent is a Canvas
  2. Create a ValueConverter CenterPointConverter that converts the Ellipse into the X or Y value of the center, depending on the ConverterParameter
  3. use element-to-element binding

    <Line X1="{Binding Ellipse1, Converter={StaticResource CenterPointConverter}, ConverterParameter=X}" X2="{Binding Ellipse2, Converter={StaticResource CenterPointConverter}, ConverterParameter=X}" Y1="{Binding Ellipse1, Converter={StaticResource CenterPointConverter}, ConverterParameter=Y}" X1="{Binding Ellipse2, Converter={StaticResource CenterPointConverter}, ConverterParameter=Y}"/>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜