开发者

XAML - How to get the name of one element in an other view

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜