好的,我在 Silverlight MVVM Light 应用程序中有以下 XAML 标记。这是观点的一部分。在视图代码隐藏中的 btnClearBodyMark 的单击事件中,我尝试使用 .Parent 属性向上遍历树,第一个父级是水平堆栈面板,然后它的父级是垂直堆栈面板,它的父级是网格,但是网格的父级是另一个网格??如何获得对按钮所属的 ListBoxItem 的引用???
<ListBox Name="listboxBodyMarkValues" ItemsSource="{Binding}" Height="Auto" Width="Auto" SelectionChanged="listboxBodyMarkValues_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<StackPanel x:Name="stackBodyMarkList" Orientation="Vertical" Margin="5" Height="Auto">
<StackPanel Orientation="Horizontal" Margin="5" Height="Auto">
<TextBlock x:Name="txtId" Width="50" Height="Auto" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding Id}" />
<ComboBox x:Name="comboDom1" Width="100" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" ItemsSource="{Binding Dom1}" SelectedItem="{Binding Dom1SelectedItem, Mode=TwoWay}" Visibility="{Binding ComboIsVisible}"/>
<Button x:Name="btnClearBodyMark" Content="Delete Body Mark" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" Click="btnClearBodyMark_Click" />
</StackPanel>
<TextBox x:Name="txtNotes" VerticalAlignment="Stretch" VerticalContentAlignment="Top" HorizontalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding ManualText, Mode=TwoWay}" AcceptsReturn="True" Margin="5" MaxWidth="400" MaxHeight="200" VerticalScrollBarVisibility="Auto" IsEnabled="{Binding ManualTextIsEnabled}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>