Reputation: 3447
I have DataTemplates where the elements don't always fill the entire cell (ie. because I increase the row height).
Now a row gets selected only if I click inside the element, if I click outside the element, but still in the row nothing happens.
How to make a WPF datagrid row selectable even if I click in between to elements.
One idea would be to listen to the MouseDown in the datagrid, but how can I identify the Row
Update: A work around is to give all the cell datatemplate a border with transparent background to fill the cell (I find this not very elegant).
Upvotes: 3
Views: 1406
Reputation: 34250
I not sure know why you think adding a "buffer" around your content is not a very elegant way to achieve the goal of enlarging the clickable region of that content.
I think that it is exactly what you should do and that it makes perfect sense architecturally, from the point of view of style, and most importantly from my point of view, for clarity and simplicity.
It is true there are other solutions that will give the same net effect to the user but the buffer approach does have this elegant property:
Programming as a whole can be rather inelegant. It is often a bunch of special cases and complicated solutions to what seem like they should be easy problems. The famous computer scientist Donald Knuth has said that he feels what makes programmers programmers is their ability to cope with these inelegant things. The things that would make a mathematician go crazy.
Upvotes: 1