make wpf datagrid row selectable on Mouse click between elements
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 t开发者_JAVA百科he 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).
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:
- If you click it and it responds, what you clicked is part of the content that responds
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.
精彩评论