xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="430" Width="525">
<Grid>
<Button x:Name="Button1" Content="Click Me" Width="90" Height="30" VerticalAlignment="Top"/>
<ListView x:Name="ListView1" SelectionMode="Single" Margin="50">
<ListViewItem>
<StackPanel x:Name="THEME_1_">
<Label Content="THEME 1"/>
<TextBlock Background="#fff7bdbd"/>
<TextBlock Background="#d0ff99"/>
<TextBlock Background="#ffc378"/>
<TextBlock Background="#fff593"/>
</StackPanel>
</ListViewItem>
<ListViewItem IsSelected="True">
<StackPanel x:Name="THEME_2_">
<Label Content="THEME 2"/>
<TextBlock Background="#bca7dd"/>
<TextBlock Background="#6dd8d6"/>
<TextBlock Background="#e086e5"/>
<TextBlock Background="#ffeab6b6"/>
</StackPanel>
</ListViewItem>
<ListViewItem>
<StackPanel x:Name="THEME_3_">
<Label Content="THEME 3"/>
<TextBlock Background="#ffe9c1"/>
<TextBlock Background="#d2b6d4"/>
<TextBlock Background="#ebf2d4"/>
<TextBlock Background="#f2b8b1"/>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
</Window>
vb.net
Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
For Each obj As Object In LogicalTreeHelper.GetChildren(CType(ListView1.SelectedItem, DependencyObject))
MessageBox.Show(obj.ToString)
Next
End Sub
Приведенные выше коды прекрасно работают.
Когда вы запустите приведенные выше коды и нажмете кнопку Button1, вы увидите, чтоMessageBox показывает вам System.Windows.Controls.StackPanel
Я хочу, чтобы MessageBox показывал мне Имя StackPanel .