Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6216581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:16:25+00:00 2026-05-24T07:16:25+00:00

I have an ItemTemplate that contains a simple button. When I click this button

  • 0

I have an ItemTemplate that contains a simple button. When I click this button I need a way to identify the row clicked to pull out the item bound to the listbox.

XAML

        <ListBox Name="DemoBox" SelectionChanged="listBox_SelectionChanged">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Height="150">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="400"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid Height="120" Grid.Column="0">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="60"/>
                            </Grid.RowDefinitions>
                            <TextBlock
                                    Grid.Row="0"
                                    Text="{Binding SomeObjProperty}"/>
                        </Grid>
                        <Grid Height="120" Grid.Column="1" Margin="0,-12,0,0">
                            <Button Click="ShowStuffOnMap_Click">
                                <Button.Background>
                                    <ImageBrush ImageSource="images/arrow.png"/>
                                </Button.Background>
                            </Button>
                        </Grid>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

click handler

    private void ShowStuffOnMap_Click(object sender, RoutedEventArgs e)
    {
        //sender is the button so ...
    }

Thank you in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:16:27+00:00Added an answer on May 24, 2026 at 7:16 am

    Why do you have Button with a click event inside a ListBox with a SelectionChanged event? This makes up for some scary UX, if they have different actions!

    The normal approach is to have a databound ListBox, and then use the SelectionChanged event to read out the selected item.

    private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var listBox = sender as ListBox;
        var selectedItem = listBox.SelectedItem as MyDataBoundType;
    
        if (selectedItem != null)
        {
            // do stuff
        }
    
        // if you use the ListBox for navigation, set the SelectedIndex to -1
        // listBox.SelectedIndex = -1;
    }
    

    But if you really really want to do it, you need to use the Tag property.

    <Button Click="ShowStuffOnMap_Click" Tag="{Binding}">
    

    And then in your event handler:

    private void ShowStuffOnMap_Click(object sender, RoutedEventArgs e)
    {
        var button = sender as Button;
        var selectedItem = button.Tag as MyDataBoundType;
    }
    

    But I still think your approach here is wrong, and stands for bad user experience, as the normal approach to a list is that the entire line in the list, is one-selection only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview that contains one linkbutton within itemtemplate. I bind this gridview
I have a repeater control that contains an ItemTemplate containing a databound label and
I have a datalist that contains a gridview inside its itemtemplate. on the item-data_bound
I have an UpdatePanel that contains a Repeater. in the ItemTemplate of the repeater
I have a gridview that contains around 16 ItemTemplate columns. The values in each
I have a repeater that contains a Telerik RadComboBox: <asp:Repeater ID=rpt runat=server> <ItemTemplate> <telerik:RadComboBox
i have a datalist that contains dynamic content. i need to enable paging to
I have a ListView that contains 3 checkboxes per row. I want to set
I have one grid view that contains some template columns. In this, the first
I have a DataGrid, with an ItemTemplate that has an image and label. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.