2016-11-15 857 views
1

我正在使用WPF數據網格來顯示一些數據,我想網格線的厚度等於一個像素,但每個單元格顯示不需要的邊框。如何擺脫它,並將所有行的厚度設置爲一個像素(如在WinForms中的DataGridView中)?如何在一個像素寬度(WPF DataGrid)中設置網格線?

XAML: 
<DataGrid HeadersVisibility="Column" SelectionUnit="Cell"> 
    <DataGrid.Columns> 
     <DataGridTextColumn Header="ID" Binding="{Binding ID}"/>          
     <DataGridTextColumn Header="Description" Binding="{Binding Description}"/> 
    </DataGrid.Columns> 
</DataGrid> 

結果: unwanted borders

+0

它可能是操作系統特定的,只是在win10嘗試過樣本,並沒有這樣的影子。 – Shakra

回答

0

這是解決方案! Settig參數RenderOptions.EdgeMode =「Aliased」 非常感謝David Kossoglyad提供的此解決方案。

<DataGrid RenderOptions.EdgeMode="Aliased" UseLayoutRounding="True" ....> 
1

這可能會爲你

<DataGrid.CellStyle> 
    <Style TargetType="DataGridCell"> 
     <Setter Property="BorderThickness" Value="1,0,0,1"/> 
     <Setter Property="BorderBrush" Value="Black"/> 
    </Style> 
</DataGrid.CellStyle> 
+0

當我將屬性GridLinesVisibility設置爲「無」值時,所有網格線都被刪除。 我需要網格線,但在一個像素寬度。 – kostey2204

+0

問題沒有解決,但加劇了。設定後 邊界變得更厚,現在等於2像素 – kostey2204

+0

只需將1,1,1,1更改爲1,0,0,1,看看它是否有幫助 –

0

做的伎倆試試這個:

<DataGrid.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Setter Property="Effect"> 
       <Setter.Value> 
        <DropShadowEffect BlurRadius="1" Opacity="0" ShadowDepth="0"/> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </DataGrid.CellStyle> 

如果這不會幫助嘗試設置相同的屬性爲DataGrid.RowStyle

+0

可惜沒幫助 – kostey2204

相關問題