I am trying to draw a simple line in WP7 XAML such as the one below. With static coordinate values this works fine.
<Line Stroke="White"
X1="1" Y1="1"
X2="200" Y2="1" />
What I need is to bind the coordinate values relative to other controls on the same Canvas based on a matching property value such as its Id or Name. Once the correct control is bound, I need to get its Left and/or Top Canvas locations. Using a vague pseudocode, here is what I would like to be able to do…
<Line Stroke="White"
X1="{Binding Canvas.Left, Source={Binding <a_control_where_a_property_equals_some_value>}}" Y1="1"
X2="200" Y2="1" />
I’ve tried a number of binding scenarios with no success. The extra complexity is that this is Windows Phone 7 (WP7) binding and not full blown XAML.
Note: All the controls are added at runtime so they are not statically defined.
Any Suggestions???
The best you can hope for is to use ElementName. Other than that, you’d need to expose a common property somewhere that both controls would be bound to. Possibly in a view-model, but it depends on your setup.
Sample of ElementName: