Paul Baxter Paul Baxter - 2 months ago 8
C# Question

How do I remove the size control from a DataGrid

I want to get rid of the row resizer on the left side of the datagrid and I cant seem to do it.

I am using WPF xaml

<DataGrid x:Name="ProcessDatagrid" Height="130" GridLinesVisibility="None" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,10,10,10" SelectionMode="Single" SelectionUnit="FullRow" AlternatingRowBackground="#FFEEEE" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" IsReadOnly="True"
SelectedCellsChanged="ProcessDatagrid_SelectedCellsChanged" CanUserResizeColumns="False" AutoGenerateColumns="False" RowDetailsVisibilityMode="Collapsed">
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Padding" Value="0" />
<Setter Property="ToolTip">
<Setter.Value>
<TextBlock Text="{Binding Path=FullName, Mode=OneWay}" />
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderThickness" Value="0" />
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name, Mode=OneWay}" Width="*"/>
<DataGridTextColumn Header="ID" Binding="{Binding Path=Pid, Mode=OneWay}" Width="50"/>
</DataGrid.Columns>
</DataGrid>


datagrid

Answer

DataGrid.RowHeaderWidth can do that:

<DataGrid
    RowHeaderWidth="0"
    ...

Or use DataGrid.RowHeaderStyle to collapse them:

<DataGrid 
    ... 
    >
    <DataGrid.RowHeaderStyle>
        <Style TargetType="DataGridRowHeader">
            <Setter Property="Visibility" Value="Collapsed" />
        </Style>
    </DataGrid.RowHeaderStyle>