我有以下XAML代码,删除了样式和格式标记:
<ListBox Name="ManageImageList">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Name="ManageImageThumbnail" Source="{Binding ImageName}" />
<StackPanel Orientation="Vertical" >
<TextBlock Name="ManageImageUrl" Text="{Binding ImageName}" />
<TextBlock Name="ManageImageComment" Text="{Binding Comment}" />
</StackPanel>
<Button Name="ManageImageDelete" ClickMode="Press" Click="ManageImageDelete_Click" Content="X" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
ListBox绑定到ObservableCollection。我想在单击按钮时将焦点放在父ListBox项上,使其成为ListBox的SelectedItem。我该怎么做?
答案 0 :(得分:2)
在点击事件中使用: -
ManageImageList.SelectedItem = ((Button)sender).DataContext;