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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:02:26+00:00 2026-05-10T20:02:26+00:00

It’s easy to bind something to the SelectedIndex of the ListBox, but I want

  • 0

It’s easy to bind something to the SelectedIndex of the ListBox, but I want every item in the ListBox be able to bind to it’s index in the list.

Might sound weird, so here’s what I’m trying to do:

<DataTemplate x:Key='ScenarioItemTemplate'> <Border     Margin='8,2,8,2'     Background='#FF3C3B3B'     BorderBrush='#FF797878'     BorderThickness='2'     CornerRadius='5'>     <DockPanel>         <DockPanel DockPanel.Dock='Top' Margin='0,2,0,0'>             <Label HorizontalAlignment='Left'                    DockPanel.Dock='Left'                    FontWeight='Heavy'                    Foreground='White'                    Content='{Binding Path=Position}'                    MinWidth='50'/>              <Label                    Content='{Binding Path=Name}'                    DockPanel.Dock='Left'                    FontWeight='Heavy'                    Foreground='white'/>             <Label                     Content='{Binding Path=Header}'                    Foreground='white'                    DockPanel.Dock='Left'/>              <TextBlock HorizontalAlignment='Right'                         Background='#FF3C3B3B'                         DockPanel.Dock='Left' Foreground='White' FontWeight='Heavy'>                 <Hyperlink Click='CloseHyperlink_Click' Tag=''>X</Hyperlink>             </TextBlock> 

I want to bind the TAG property of the hyperlink to the index of the item in question. So that when the user clicks the hyperlink, I can determine what item caused the event using the TAG property of that hyperlink.

var hyperlink = (Hyperlink)sender; var index = Convert.ToInt32(hyperlink.Tag); 

Suggestions?

  • 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-10T20:02:26+00:00Added an answer on May 10, 2026 at 8:02 pm

    As far as I know, there isn’t really a property that indicates the index of your item. If you have access to the original list of items to which your ListBox is bound, you could access the DataContext of your Hyperlink to determine the index of your item, like this:

    var hyperlink = (Hyperlink)sender; var item = (SourceType)hyperlink.DataContext; int index = sourceList.IndexOf(item); 

    Alternatively, you could call ItemsControl.ContainerFromElement on the hyperlink to get the ListBoxItem associated with the Hyperlink and then find the ListBoxItem’s position in the ListBox, but it doesn’t really get you anything that you didn’t already have.

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

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • 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 Couldn't you do something like (pseudocode) <allEvents switchValue='Error' name='blahblah'> <listeners><add… May 11, 2026 at 2:23 pm
  • added an answer This happens because C# considers methods declared in a type… May 11, 2026 at 2:23 pm
  • added an answer The default scope is package-private. All classes in the same… May 11, 2026 at 2:23 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
It seems to me obfuscation is an idea that falls somewhere in the security

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.