Hi Markus,
You can set the style for DataGridColumnHeader and DataGridCell without Key. The style then affects all cells.
WPF - C# Desktop App - DateGrid - TextAlignment Center for the cells
Hello,
<DataGrid Grid.Column="1"
ItemsSource="{Binding View2}"
IsReadOnly="True"
AutoGenerateColumns="False" Margin="54,669,429,22" FontSize="18">
<DataGrid.Columns>
<DataGridTextColumn Header="Slot Nummer" Binding="{Binding SlotNo}"/>
<DataGridTextColumn Header="Materialnummer" Binding="{Binding Number}"/>
How do I get cells as text alignment in the middle.
And how can I make the active line green from the code behind?
Thanks for answers in advance.
Best regards Markus
-
Peter Fleischer (former MVP) 19,331 Reputation points
2020-07-27T04:06:52.12+00:00
2 additional answers
Sort by: Most helpful
-
Peter Fleischer (former MVP) 19,331 Reputation points
2020-07-26T04:51:31.453+00:00 Hi Markus,
You can set the style for DataGridCell without Key. The style then affects all cells. -
DaisyTian-1203 11,631 Reputation points
2020-07-27T03:21:26.18+00:00 1.Set SelectionUnit="FullRow" for your DataGrid to make it selected by row.
2.Use ElementStyle="{StaticResource mytext}" for the DataGridTextColumn to make the active text to Green in the code:
In the cs code add : this.dataGrid.Resources["columnForeground"] = Brushes.Green;
Here is the xaml code: