Binding to UserControl action in Silverlight?
Have a look at some questions on SO, but nobody answers my question.
What I want to do: I have a custom control (lets call it A) that moves across the canvas using a storyboard. And I want to bind another custom canvas control (lets call it B) to the first control.
Using TransformToVisual (Application.Current.RootVisual) I can get the actual position of control A, but I can't figure out how to get the binding to B's Canvas.Left and Canvas.Top.
Has anyone figured out how to accomplish this task? Or lead me in the right direction?
source to share
I'm assuming you are repositioning control A by updating the Canvas.Left and Canvas.Right properties? If so, you don't need to use TransformToVisual, you can simply bind their Canvas Top and Left properties together:
<Canvas >
<TextBlock x:Name="ControlB"
Text="Some Text"
FontSize="15"
Canvas.Left="{Binding ElementName=ControlA, Path=(Canvas.Left)}"
Canvas.Top="{Binding ElementName=ControlA, Path=(Canvas.Top)}"/>
<TextBlock x:Name="ControlA"
Text="Some Text"
FontSize="13"
Canvas.Left="100"
Canvas.Top="100"/>
</Canvas>
Best regards, Colin E.
source to share