开发者

Silverlight: Give focus to a parent ListBox item when clicking a child button

I have the following XAML code, having removed the styling and formatting tags:

<ListBox Name="ManageImageList">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <Image Name="ManageImageThumbnail" Source="{Binding ImageName}" />
                <StackPanel Orientation="Vertical" >
                    <TextBlock Name="ManageImageUrl" Text="{Binding ImageNa开发者_Python百科me}" />
                    <TextBlock Name="ManageImageComment" Text="{Binding Comment}" />
                </StackPanel>
                <Button Name="ManageImageDelete" ClickMode="Press" Click="ManageImageDelete_Click" Content="X" />
           </StackPanel>
        </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

The ListBox is bound to an ObservableCollection. I would like to give focus to the parent ListBox item when the button is clicked, making it the SelectedItem of the ListBox. How do I do this?


In the click event use:-

 ManageImageList.SelectedItem = ((Button)sender).DataContext;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜