日期:2014-05-17 浏览次数:21159 次
<Window x:Class="WPF熊俊.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF熊俊" ContentRendered="Window_ContentRendered">
<Border Name="border1">
<Button x:Name="button1" Content="Button" Click="Button_Click"/>
</Border>
</Window>
private void Button_Click(object sender, RoutedEventArgs e)
{
EnumVisual(this);
}
public void EnumVisual(DependencyObject dcy)
{
int count = VisualTreeHelper.GetChildrenCount(dcy);
for (int i = 0; i < count; i++)
{
DependencyObject childdcy = VisualTreeHelper.GetChild(dcy, i);
Border border = childdcy as Border;
if (border != null)
MessageBox.Show(border.Name);
EnumVisual(childdcy);
}
}