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

  • Home
  • SEARCH
  • 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 58k
  • Answers 58k
  • 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've been dealing with Japanese encodings for almost 20 years… May 11, 2026 at 8:44 am
  • added an answer Visiting http://www.keishalexie.com/imd465/forum.php?getTutorials=1 (Which is what your code is calling) returns… May 11, 2026 at 8:44 am
  • added an answer You have multiple NICs and are multi-homed? May 11, 2026 at 8:44 am

Top Members

Trending Tags

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

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.