How to HitTest in a WPF Grid Panel to find column index.
- by John
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.