views:

626

answers:

1

Let's say I have a simple UserControl with no codebehind:

<UserControl
xmlns= ....
x:Class="TrafficLight.LightControl">
<Grid x:Name="LayoutRoot">
<Grid x:Name="Light" >
  <Ellipse  x:Name="MyColor" Fill="{**I need bind this field to UserControl.Foreground**}" Stroke="#FF000000" />
  <Ellipse  x:Name="Shade" Fill="#E4555555" />
</Grid>
</Grid>

And use this UserControl on the Page:

<TrafficLight:LightControl x:Name="red" Foreground="#FFFEF100" **<= I need to bind MyColor.Fill with this property**/>

How I can implement this scenario?

A: 

Okay, I looked into various methods and without ElementName binding (something that Silverlight 3 introduces), which Microsoft didn't include for Silverlight, it's a tough one. Without some code behind, this is not an easy task to achieve.

This blog post gives some detail on how you could achieve this, but be aware that you will need to write some code.

Jeff Yates
Thanks. I've try to use it, but no effect.<Ellipse x:Name="Color"> <TL:BindingHelper.Binding> <TL:BindingProperties TargetProperty="Fill" SourceProperty="Foreground" RelativeSourceSelf="False" ElementName="MyUserControlName"/> </TL:BindingHelper.Binding></Ellipse>
FFire
Hmm, that's a shame. I'll try and take a look later today, and see if we can't sort this one out for you. :)
Jeff Yates