开发者

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

开发者 https://www.devze.com 2023-01-18 18:06 出处:网络
I have the following XAML code, having removed the styling and formatting tags: <ListBox Name=\"ManageImageList\">

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

精彩评论

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