Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Datagrid textalign and background problem

$
0
0
Hello. I need a bit of help with something. I develop an WPF app and I have the following problem. I want to color the backgroup of a column acording to it's value (status = ONLINE -> Green, status = OFFLINE ->Red). ALl but, it work's but when I want to "Center" the text my cell is not fully colored, only the text background is colored. Here is the code I wrote: 
<DataGridTextColumn Header="STATUS" Binding="{Binding EMP_STATUS, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="50" Width="*" ><DataGridTextColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center" /></Style></DataGridTextColumn.HeaderStyle><DataGridTextColumn.ElementStyle><Style TargetType="{x:Type TextBlock}"><Style.Triggers><Trigger Property="Text" Value="OFFLINE"><Setter Property="Background" Value="Red"/></Trigger><Trigger Property="Text" Value="ONLINE"><Setter Property="Background" Value="Green"/></Trigger></Style.Triggers></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.CellStyle><Style><Setter Property="FrameworkElement.HorizontalAlignment" Value="Center"/></Style></DataGridTextColumn.CellStyle></DataGridTextColumn>
And here is the final datagrid.Is it possible to color all the cell and to have the text centered in the same time?

Viewing all articles
Browse latest Browse all 18858


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>