Reputation: 11734
Seen some questions on SO but none answers my question.
What I want to accomplish: I have a custom control (lets call it A) which moves around the canvas using a storyboard. And I want to bind another custom control's canvas (lets call it B) position onto the first control.
Using the TransformToVisual(Application.Current.RootVisual) I can get the actual position of control A, but I can't figure out how to get a binding to B's Canvas.Left and Canvas.Top on this.
Has anyone figured out how to accomplish this task? Or get me pointed into the right direction?
Upvotes: 2
Views: 127
Reputation: 70142
I presume you move the position of control A by updating its Canvas.Left and Canvas.Right properties? If this is the case, you do not need to use TransformToVisual, you can just bind their Canvas Top & 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>
Regards, Colin E.
Upvotes: 1