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?
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.