I have a component which call 2usercontrols. Usercontrols1 :(code part)
<StackPanel Name="NeedThisName" >
</StackPanel>
Usercontrols2 :(code part)
<Button >
<Button.Template>
<ControlTemplate>
<Rectangle >
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=????}" Opacity="0.75" Stretch="None" >开发者_StackOverflow;
<VisualBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.5" ScaleY="0.5" />
</TransformGroup>
</VisualBrush.RelativeTransform>
</VisualBrush>
</Rectangle.Fill>
</Rectangle>
</ControlTemplate>
</Button.Template>
I would like to get the name in usercontrol1 ("NeedThisName") to specify to the Visual property of the visualbrush.
You should not access controls of one usercontrol from another.
Try to comminicate between them only using (Dependency-)properties and / or databinding to ViewModel classes. For example, your user control could have a property "RectangleFill" which the fill of the rectangle is bound to.
精彩评论