How to bind a UserControl property?

Say I have a simple UserControl without code:

<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 can I implement this scenario?

+3
source share
1 answer

Well, I looked at various methods, and without the ElementName binding (something that represents Silverlight 3), which Microsoft did not include in Silverlight, it is very difficult. Without any code behind, this is no easy task.

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

0
source

Source: https://habr.com/ru/post/1706061/


All Articles