2017-10-13 36 views
0

我strugling找到一種方法,使這項工作:WPF數據網格邊界刷不工作

<DataGrid x:Name="name" CanUserAddRows="false" 
      IsReadOnly="true" ItemsSource="{Binding}"> 
    <DataGrid.CellStyle> 
     <Style TargetType="DataGridCell"> 
      <Setter Property="BorderThickness" Value="1"/> 
      <Setter Property="BorderBrush" Value="Red"/> 
     </Style> 
    </DataGrid.CellStyle> 
</DataGrid> 

我只是想改變細胞的邊框的顏色,爲什麼它要這麼複雜? :/

+0

「不工作」很難解釋。它是否以你能描述的任何特定方式失敗? –

+0

邊框細胞保持黑色 – jairhumberto

回答

0
<DataGrid 
    x:Name="name" 
    CanUserAddRows="false" 
    IsReadOnly="true" 
    ItemsSource="{Binding}" 

    HorizontalGridLinesBrush="DeepSkyBlue" 
    VerticalGridLinesBrush="YellowGreen"> 
</DataGrid> 
+0

男人,那就是我一直在尋找的!謝謝!我沒有意識到應該在主標籤中設置邊框。我花了幾個小時在模板和DataGrid.CellStyle – jairhumberto

+0

我很驚訝CellStyle沒有爲你工作;我嘗試了你所做的,並立即奏效。但是黑線仍然存在於其間。所以我去了DataGrid尋找一種方法來關閉這些功能,找到'GridLinesVisibility',並開始尋找名稱中帶有'GridLines'的其他屬性。答對了。 –

+1

令我驚訝的是,當你問到它的時候它就起作用了。但它不起作用。我嘗試了所有的事情,但是當我發佈這個問題時,我把問題的標籤清理得更簡潔。雖然效果不是我想要的 – jairhumberto