日期:2014-05-17 浏览次数:20928 次
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border1">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Border Name="border2">
<Grid Name="grid1" HorizontalAlignment="Left" Width="596">
<Border Name="border3" />
<Button x:Name="button1" Content="Button" Click="Button_Click" Margin="217,303,258,155"/>
</Grid>
</Border>
private void Button_Click(object sender, RoutedEventArgs e)
{
var count = VisualTreeHelper.GetChildrenCount(this);
if (count > 0)
{
for (var i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(this, i);
var t = child as Border;
if (t != null)
MessageBox.Show(t.Name);
}
}
}