2

I want to remove lines under the text in datagrid. The screen shot of the application is here.

   <DataGrid Name="ProductKeyTable" AutoGenerateColumns="FALSE" IsReadOnly="True" 
              Grid.Row="2" Margin="15" GridLinesVisibility="Horizontal">
        <DataGrid.Columns>
            <DataGridTextColumn Header="ID" Binding="{Binding ID}" Visibility="Collapsed"></DataGridTextColumn>
            <DataGridTextColumn Header="Product Key" Binding="{Binding ProductKeyStr}"  Width="3*">
                <DataGridTextColumn.HeaderStyle>
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="HorizontalContentAlignment" Value="Center" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.HeaderStyle>
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="TextBlock.TextAlignment" Value="Center" />
                        <Setter Property="TextBlock.VerticalAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
            <DataGridTextColumn Header="Generation Date" Binding="{Binding GenerationDate}"  Width="3*">
                <DataGridTextColumn.HeaderStyle>
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="HorizontalContentAlignment" Value="Center" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.HeaderStyle>
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="TextBlock.TextAlignment" Value="Center" />
                        <Setter Property="TextBlock.VerticalAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
            <DataGridTextColumn Header="Current Machines" Binding="{Binding CurrentMachines}"  Width="3*">
                <DataGridTextColumn.HeaderStyle>
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="HorizontalContentAlignment" Value="Center" />
                        <Setter Property="VerticalContentAlignment" Value="Center" />
                    </Style>
                </DataGridTextColumn.HeaderStyle>
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="DataGridCell">
                        <Setter Property="TextBlock.TextAlignment" Value="Center" />
                        <Setter Property="TextBlock.VerticalAlignment" Value="Center" />
                        <Setter Property="BorderThickness" Value="0 0 0 0" />
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
            <DataGridTemplateColumn  Width="80">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Button Margin="2" Background="SkyBlue" Foreground="White" FontSize="12"  BorderThickness="0 0 0 0"  Width="50" Height="30" Click="DeleteProductKeyClick">Delete</Button>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>

I tried setting the border thickness of the cell to 0, but it does nothing.

Removing VerticalContentAlignment property will work, but the text is not centered.

Any ideas? Thanks.

QIZHI WEN
  • 21
  • 1
  • Try with setting Cell margin -1 or with Vertical/Horizontal line brush in dataGrid – sTrenat Nov 29 '17 at 18:22
  • @sTrenat setting margin-1 does not work. Line brush will remove all the grid lines. – QIZHI WEN Nov 29 '17 at 18:44
  • Little dirty, but try with VerticalContentAlignment = Strech and set padding as, e.g 0,7,0,0 – sTrenat Nov 29 '17 at 19:07
  • Problem solved! Setting padding directly does not work, but setting margin in work according to [link](https://stackoverflow.com/questions/5246745/set-a-padding-on-datagridcells-in-wpf) . Thanks @sTrenat – QIZHI WEN Nov 29 '17 at 21:14

0 Answers0