views:

140

answers:

1

Another beginner WPF question from me :)

Ok, so I have a User Control added to a Canvas. In another area of the application I have two TextBoxes that will get 2 values : X and Y. I need a two-way binding between the user control's top left corner coordinates and those 2 textboxes. I don't mind implementing a Converter or doing some calculations, but I need a push in the right direction from a more experienced WPF developer.

A: 
<UserControl Canvas.Left="{Binding Text, ElementName=myFirstTextBox, Mode=TwoWays}"
             Canvas.Top="{Binding Text, ElementName=mySecondTextBox, Mode=TwoWays}"  ... />

But I can only strongly recommend you to use some sort of custom ValidationRule on your TextBoxes, in order to disallow any input that does not represent a valid number, otherwise you will get a nice crash.

Aurélien Ribon
Alternately, you can also bind from Text on your text box to {Binding (Canvas.Left), ElementName=myUserControl, Mode=TwoWay}
Dan Bryant
Thanks Aurelien, I thought that would be more complicated.
morsanu
Thank the magic of WPF. Coming from the Java world, it is impossible to go back :)
Aurélien Ribon