I want to run some code when the user single clicks on any given ListBox item. My setup is a ListBox with a custom ItemsPanelTemplate (Pavan's ElementFlow). Based on the position data that comes in to MouseLeftButtonDown is there a way to tell which item is was clicked? This is made a bit more difficult (or more confusing) by the custom ItemsPanelTemplate.
Get a WPF ListBox item from MouseLeftButtonDown
5.9k Views Asked by James Cadd At
1
There are 1 best solutions below
Related Questions in WPF
- Sorting a List by its property renames all the objects in the List
- Can't open new instance of another window in my app, in WPF .NET 8
- Binding forecolour and ToolTip to a DataGrid
- how to create Infinite Upgrades in a clicker game
- Try Catch exception is not catching the unhandled exception
- Assigning an object to another doesn't raise PropertyChanged event in WPF
- Masking input in TextBox
- What should I do if Visual Studio has a restriction on creating files with a long name or a long path to these files?
- reading configuration file (mytest.exe.config)
- WPF Windows Initializing is locking the separated thread in .Net 8
- How to bind to the DataContext ViewModel of another view?
- mouse coordinates in image go below 0 and above width
- WPF pop up is behaving differently in English language PC and Japanese language PC
- Multi level project reference using dll
- Unable to unzip archive .NET framework
Related Questions in LISTBOX
- How to MakeScreenshot fullpage on Delphi
- How to populate a ListBox with SendMessage?
- Tkinter: How to delete items in listbox from a different window Tkinter
- How to change an item in a list forever?
- Tkinter: Listbox not populating from function call, populates from list
- TypeError: 'StringVar' object is not iterable -- tkinter ListBox()
- cdk listbox with selection "forced by code" doesn´t show as selection "by hand"
- How to save as string each item selected in listbox
- VBA listbox_click event - itemsselected not registering
- ListBox does not include newly added lines to source table because of RowSource
- Synchronization Delay Between Context Menu and Selected Row in WPF ListBox
- Is there a more efficient way to search for text from ListBox in a text in C#?
- How can I divide 2 namens and convert them to a E-Mail Adress with lixtboxes? (Visual Baisc 2010)
- How do I add all items form my database to my listbox and a counter?
- Listbox not showing data in mvvm wpf
Related Questions in MOUSEEVENT
- Detect Mouse Clicks; Terminate Program on Scroll Wheel Movement
- how to create a mouseEvent with target in typescript without dispatching?
- How to make (mulitple) image appear when clicking?
- An HTML Link Element ("a") Refuses to Attach Itself to Event Listener
- "contextmenu" Event interrupts "onmousemove" from executing a function
- right click event for wxDataViewListCtrl
- How to save the brush event when hovering over elements with their own events
- Mouse input not blocked when running Python code on Ubuntu using pynput library
- createJS does not reconize currentTarget
- How To Make Mouse Recoil be smooth?
- What's the benefit of multiline code with multple variables compared to combined actions pygame.mouse.getpos() that combine them
- How can I prevent the behavior of swipe backward of browser on mac?
- Adding a circle which follows a mouse and changes colours based on the current colour | Interactive SVG Colouring Page | Using JavaScript
- How to move the background image by clicking and dragging the mouse smoothly?
- How to add an event listener to elements (or children)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can have an ItemContainerStyle, and specify an EventSetter in it:
Then, in the handler of the MouseLeftButtonDown, the "sender" will be the ListBoxItem.
ALSO, if you don't want to use this method, you can call HitTest to find out the Visual object at a specified position: