I have a datagrid which I define the styles and columns in code behind as following :
My_Data_Grid.ItemsSource = an_observableCollection ;
Style my_Style = new System.Windows.Style(typeof(DataGridCell));
DataGridTextColumn a_Column = new DataGridTextColumn();
a_Column.Header = "_Header_";
a_Column.Binding = new Binding("index");
a_Column.Width = 80;
a_Column.CellStyle = my_Style;
My_Data_Grid.Columns.Add(a_Column);
This snippet code will have a result like the following screenshot :
I want to change the alignment, so that I apply the following changes to previous code :
my_Style.Setters.Add(
new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center));
my_Style.Setters.Add(
new Setter(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center));
The effect will be the following screenshot :
As you notice, the alignment is fine now; but the selection is not the whole cell any more ! only the text is highlighted as selected !
Doest any one has any ideas how I can fix this problem ?