Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could create an style in like these samples to highlight and align I have:</p> <pre><code> &lt;!-- Right Aligned Cell --&gt; &lt;Style x:Key="RightAlignedCell" TargetType="{x:Type dg:DataGridCell}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type dg:DataGridCell}"&gt; &lt;Grid Background="{TemplateBinding Background}"&gt; &lt;ContentPresenter HorizontalAlignment="Right" VerticalAlignment="Center"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="dg:DataGridCell.IsSelected" Value="True"&gt; &lt;Setter Property="Background" Value="#356815" /&gt; &lt;Setter Property="Foreground" Value="#e2fce2" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;!-- Center Aligned Cell --&gt; &lt;Style x:Key="CenterAlignedCell" TargetType="{x:Type dg:DataGridCell}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type dg:DataGridCell}"&gt; &lt;Grid Background="{TemplateBinding Background}"&gt; &lt;ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="dg:DataGridCell.IsSelected" Value="True"&gt; &lt;Setter Property="Background" Value="#356815" /&gt; &lt;Setter Property="Foreground" Value="#e2fce2" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>later you put:</p> <pre><code>&lt;dg:DataGrid x:Name="dg" AutoGenerateColumns="False" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" ItemsSource="{Binding}" SelectionMode="Single" ...&gt; &lt;dg:DataGridTextColumn Header="Total Amount" Width="110" CellStyle="{StaticResource RightAlignedCell}" Binding="{Binding Total,StringFormat={}\{0:N0\}}" IsReadOnly="True"/&gt; &lt;dg:DataGridTextColumn Header="Enter Date" Width="110" CellStyle="{StaticResource CenterAlignedCell}" Binding="{Binding EnterDate,StringFormat={}\{0:dd/MM/yyyy\}}" IsReadOnly="True"/&gt; </code></pre> <p>....</p> <p>I hope this works for anyone who's wandering how to highlight a full row in WPF DataGrid.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload