Nick Kitto Nick Kitto - 6 months ago 145
C# Question

C# - Removing right edge row border in WPF DataGrid

I am trying to remove the far right GridLine in a WPF GridView.
Here is an example .xaml

<Window x:Class="Pack.ExampleForm"
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
Width="400" Height="300">

<DataGrid Margin="5" AutoGenerateColumns="False"
CanUserReorderColumns="False" HeadersVisibility="Column">

<DataGridTextColumn Binding="{x:Null}" CanUserResize="False"/>
<DataGridTextColumn Binding="{Binding Path=Key}" Header="Request Header" Width="*"/>
<DataGridTextColumn Binding="{Binding Path=Value}" Header="Value" Width="*"/>

<local:RequestHeader Key="Subject 1" Value="Body 1" />
<local:RequestHeader Key="Subject 1" Value="Body 1" />

However this has the far right gridline, as show in the designer, circled in yellow.


Is there any way to remove this and have no border, as it is on the left side. Would prefer to do this in the .xaml if possible.


Hm, it is just sneaky workaround, but... :)

<DataGridTextColumn Binding="{Binding Value}" Width="*">
        <Style TargetType="DataGridCell">
            <Setter Property="Margin" Value="0,0,-1,0"></Setter>