Nov 17, 2008 at 11:31 AM


I'm still having problems to select a new row or capturing a click into a cell when the cell has HorizontalAlignment=Right. In that case the textbox inside the cell has not the width of the column and I need to click directly at the content of the cell.


Unfortunately I could not find an appropreate event to handle that situation or how to get the width of the column.


I tried the DataGrid_PreviewMouseLeftButtonDown event and the DataGridCell_PreviewMouseLeftButtonDown but I could not find the correct properties.


Does anyone has an approach to solve this problem?


Many thanks in advance.



Nov 17, 2008 at 6:39 PM
WPF is tricky...and I still claim to be a beginner. That being said...

What it sounds like you're trying to do is have a textbox fill the width of a column, and then whenever the cell is clicked, switch into editing mode?

In that case, might the HorizontalContentAlignment="Stretch" property on the textbox come in handy?
As well as this article:
As to finding the width of the column, I believe you can use the ActualWidth property.

I don't know if these will work at all, but maybe it'll give you a place to start? Good luck!
Nov 17, 2008 at 9:26 PM
Hi rschoenrock,
Thank you for your tip.

Unfortunately this: <Setter Property="HorizontalContentAlignment" Value="Stretch" /> also does not work for the cellStyle I'm using, cannot see any changes.

What I wanted to say is, that the selection of the row does not work correctly in case of HorizontalAlignment=Right or HorizontalContentAlignment=Right and the other is 'Stretch'.
When I click into the 'empty' area of the cell, the row has not be selected but the event DataGridCell_PreviewMouseLeftButtonDown has fired.

I'm using the single-click-editing-approach for checkboxes and comboboxes. This works fine when clicking into these kind of cells.