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 138825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:19:33+00:00 2026-05-11T07:19:33+00:00

I have a ListBox that has a custom DataTemplate assigned to it, so that

  • 0

I have a ListBox that has a custom DataTemplate assigned to it, so that it can correctly display it’s content – a custom ‘Accessory’ (which consists of three string properties) object per row. Additionally, there is a button on each row. That button should trigger an event that adds the selected accessory to a MemoryList. Here is the DataTemplate:

    <DataTemplate x:Key='AccessoryListBoxTemplate'>         <StackPanel>              <!--Truncated-->                     <TextBlock FontFamily='Avenir Next LT Pro' VerticalAlignment='Center' FontSize='14' Text='{Binding Path=AgilityHeader}' Margin='3,0,0,0' Grid.Column='0' />                     <TextBlock FontFamily='Avenir Next LT Pro' VerticalAlignment='Center' FontSize='14' Text='{Binding Path=ItemNumber}' Grid.Column='1' />                     <TextBlock FontFamily='Avenir Next LT Pro' HorizontalAlignment='Right' VerticalAlignment='Center' Text='{Binding Path=Price}' FontSize='14' Grid.Column='2' />                     <Button x:Name='ButtonAccessoryAddToMemoryList' VerticalAlignment='Center' Click='buttonAccessoryAddToMemoryList_Click' HorizontalAlignment='Right' FontSize='14' Width='80' Grid.Column='3' Margin='0,5,0,5'>Minneslista</Button>                 </Grid>             </StackPanel>         </StackPanel>     </DataTemplate> 

And here is the ListBox:

<ListBox Grid.ColumnSpan='3' Grid.Row='1' BorderThickness='0' x:Name='ListBoxAccessories' ItemTemplate='{StaticResource AccessoryListBoxTemplate}' HorizontalContentAlignment='Stretch' ItemsSource='{Binding}' SelectedIndex='-1' IsEnabled='True' /> 

The problem I’m having is this – I cannot reliably identify on which row ButtonAccessoryAddToMemoryList is clicked, since the row that the button is on is not set as the SelectedItem for the ListBox if the user doesn’t first select the row and then push the button – and honestly, who does that? 🙂

How should I go about identifying which button was pressed? Any help would be greatly appreciated. Thanks!

[EDIT] Thanks to Chadwick for that answer. Works perfectly. [/EDIT]

  • 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. 2026-05-11T07:19:34+00:00Added an answer on May 11, 2026 at 7:19 am

    If what you’re really after is to know which Accessory object was clicked on you can set the Tag property of the button:

    <Button x:Name='ButtonAccessoryAddToMemoryList' Tag='{Binding}' Click='buttonAccessoryAddToMemoryList_Click' ... >Minneslista</Button> 

    and then cast out the object in the click handler:

    private void ButtonAccessoryAddToMemoryList(object sender, RoutedEventArgs e) {     Button b = e.Source as Button;     Accessory a = b.Tag as Accessory; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I have found a solution to this problem. Applying an… May 11, 2026 at 11:23 am
  • added an answer Don't declare variables above the block where they'll be used… May 11, 2026 at 11:23 am
  • added an answer Set the HTTP request timeout. May 11, 2026 at 11:23 am

Related Questions

I have a ListBox that has a style defined for ListBoxItems. Inside this style,
In Silverlight, I have a Vertical ListBox that has a Horizontal ListBox for each
I have a listbox that is databound to a Collection of objects. The listbox
I have a ListBox that when in focus, and when I have an item
I have a ListBox that during development I had the items in the ListBox
I have a ListBox control that I want to change into having a toggle
I have a ListBox with a StackPanel that contains an image and label. <ListBox.ItemsPanel>
I have a composite control that contains a ListBox child control. On postback, the
I have a function that presents the user a combo-box. def select_interface(interfaces) list_box :items
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.