I am using WPF4.0 DataGrid. Double-clicking on a cell in a new row works fine , unless I add a cell style to this column. For example, I have a numeric column where I want the data to be aligned right, so xaml looks like this:
<DataGridTextColumn Binding="{Binding Path=ImpaId}" CellStyle="{StaticResource CellRightAlign}"> <DataGridTextColumn.Header> <TextBlock Style="{StaticResource DataGridHeader}">Impa</TextBlock> </DataGridTextColumn.Header> </DataGridTextColumn>
If the style in the share is simple:
<Style x:Key="CellRightAlign"> <Setter Property="Control.HorizontalAlignment" Value="Right" /> </Style>
The resulting selectable area in a new line is displayed on the image as this small blue area. This is a very small goal for the user who hits, and this is the most likely column with which they want to start a new line.

If I delete CellStyle, the area will work as desired, but, of course, I will lose the correct alignment.

Does anyone know how to achieve both?
Things i tried
- Setting TargetNullValue to bind to a format with a certain width. This works with existing lines, but does not affect the new line.
- Setting MinWidth in the column, this did not affect the width of the selected row area.
The thing that worked:
Using the information from @AngelWPF's answer, I was able to switch from using CellStyle to using ElementStyle as follows:
<DataGridTextColumn Binding="{Binding Path=ImpaId}" CellStyle="{StaticResource CellRightAlign}">
Has become
<DataGridTextColumn Binding="{Binding Path=ImpaId}" ElementStyle="{StaticResource CellRightAlign}">
wpf xaml datagrid
Tod Oct 17 '11 at 22:30 2011-10-17 22:30
source share