views:

167

answers:

2

If I make a UserControl, it has numbers properties. How I can use them? My UserControl contained several Shapes and I need to bind a Foreground property to all Shape.Fill. But I do not know how to do it.

A: 

If you set your properties to Public, you will be able to access your UserControl's properties from outside its own class.

I'm not sure if this is your issue though. Please elaborate on your issue.

Jon
A: 
  1. Use element name binding inside your user control with an existing brush dependency property
<UserControl x:Name="myUC" ...>
     <Rectangle Fill="{Binding ElementName=myUC, Path=Background}" />
     <Rectangle Fill="{Binding ElementName=myUC, Path=Background}" />
     <Rectangle Fill="{Binding ElementName=myUC, Path=Background}" />
</UserControl>
  1. Use element name binding inside your user control with a new brush dependency property.
<UserControl x:Name="myUC" ...>
     <Rectangle Fill="{Binding ElementName=myUC,Path=ShapeBackground}" />
     <Rectangle Fill="{Binding ElementName=myUC, Path=ShapeBackground}" />
     <Rectangle Fill="{Binding ElementName=myUC, Path=ShapeBackground}" />
</UserControl>
markti