views:

22

answers:

1

Hi folks,

I create a C# - Silverlight 4 Application, that consists of some User Controls visually connected by the LineArrow object. The UserControls (and the LineArrows too) are dynamically added to a Canvas in the Code-behind.

I want to bind the Canvas.LeftProperty, Canvas.TopProperty, Width and Height of the LineArrow to the two UserControls that this LineArrow connects, so that those properties change depending on the positions of the two connected UserControls.

I fiddled around a bit with the Binding - object and the SetBinding-method of the LineArrow, but had no success yet. Maybe some one here can give me a little example, how to achieve that binding?

The Top-Left of the LineArrow shall be in the center of the first UserControl and the Bottom-Right at the Top-Center of the second UserControl.

Thanks in advance, Frank

A: 
control1.SetBinding(Canvas.Top,
    new Binding { Source = lineArrow, Path = "(Canvas.Top)", Converter = new AdjustPositionConverter() };

The converter is just a name I made up. You will probably need to write a converter to shift the position around so that it lines up correctly to where you want it, but this binding should be a good start.

Stephan
Thanks a lot! Your approach works.
Aaginor