Search code examples
c#wpfxamldatagridwpfdatagrid

WPF DataGrid hide selection buttons


I'm trying to use the WPF DataGrid to present a completely static, flat and readonly columnar view.

I've tried the ListView with a GridView as well, but that offers less styling options.

Here's what I've got so far:

Screenshot

Unfortunately this still has some strange buttons in the columns and on each row (the grey sections).

I've set IsHitTestVisible to false to prevent the user clicking them, but ideally I'd like for them to not be there (or at the very least be invisible).

Here's the XAML styling I'm applying:

<Style x:Key="{x:Type DataGridColumnHeader}" TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="FontWeight" Value="SemiBold" />
</Style>
<Style x:Key="{x:Type DataGrid}" TargetType="{x:Type DataGrid}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="CanUserAddRows" Value="False" />
    <Setter Property="CanUserDeleteRows" Value="False" />
    <Setter Property="CanUserReorderColumns" Value="False" />
    <Setter Property="CanUserResizeColumns" Value="False" />
    <Setter Property="CanUserResizeRows" Value="False" />
    <Setter Property="CanUserSortColumns" Value="False" />
    <Setter Property="AutoGenerateColumns" Value="False" />
    <Setter Property="Margin" Value="5" />
    <Setter Property="GridLinesVisibility" Value="None" />
    <Setter Property="IsReadOnly" Value="True" />
    <Setter Property="SelectionUnit" Value="FullRow" />
    <Setter Property="IsHitTestVisible" Value="False" />
</Style>

This is practically perfect apart from those buttons...


Solution

  • Those are row headers, not buttons I think. The Datagrid has a property to show/hide row and column headers:

    <Setter Property="HeadersVisibility" Value="Column" />
    

    Actually the value needs to be column, if you want to keep the column headers.