How to HitTest in a WPF Grid Panel to find column index.
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-03-24T09:02:57Z
Indexed on
2010/03/24
9:43 UTC
Read the original article
Hit count: 718
Hi. We need to create a "timeline" feature where a user is allowed to drag and draw "time spans" into a WPF grid (we thought this better than a Canvas since it has resizing capabilities). Each span spans multiple columns, but only one row.
We utilize the PreviewMouseDown/Up/Move events to see when the user clicks, drags, and releases the mouse.
On the "Down" we create a new rectangle and on the "Move" we resize the rectangle, settings its ColumnSpan property to the correct value every time the mouse enteres the next column. At this point the grid has 48 1-star-sized columns. How do we find out which column the user has clicked on? Right now we are unable to find the column using the VisualTreeHelper.HitTest function.
We would like to position the rectangle correctly via Grid.SetColumn(rect, X) and then resize it as needed using Grid.SetColumnSpan(rect, Y)
Has anyone done something like this before and can help us? Or, is there a better way to draw what we need?
Thanks.
© Stack Overflow or respective owner