FindAncestor 从1开始,1层层向上找

   <StackPanel
       Name="Parent_222"
       Width="100"
       HorizontalAlignment="Center"
       VerticalAlignment="Center">
       <StackPanel
           Name="Parent_2"
           Width="100"
           HorizontalAlignment="Center"
           VerticalAlignment="Center">
           <Border Name="Parent_1">
               <StackPanel x:Name="Parent_0" Orientation="Vertical">
                   <!--  Parent_2  -->
                   <Button Height="50" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}, AncestorLevel=2}, Path=Name}" />
                   <!--  Parent_0  -->
                   <Button Height="50" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}, AncestorLevel=1}, Path=Name}" />
                   <!--  Parent_222  -->
                   <Button Height="50" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}, AncestorLevel=3}, Path=Name}" />
               </StackPanel>
           </Border>
       </StackPanel>
   </StackPanel>

  

FindAncestor 从1开始,1层层向上找

 

posted @ 2024-08-01 17:09  十年之前,十年之后  阅读(13)  评论(0)    收藏  举报