<Grid Name="rootGrid">
<Grid Name="myGrid" Width="150" Height="150" Background="LightBlue">
<Button Name="btn" Click="btn_Click" Width="80" Height="25" Content="click"/>
</Grid>
</Grid>
后台:
private void btn_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
var a = VisualTreeHelper.GetParent(btn);
}
<pre id="best-content-1141229721" accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); line-height: 24px; background-color: rgb(243, 255, 236);">然后你断点看下a,就会发现它就是button的父容器myGrid