问题
I have an ItemsControl which uses a Grid
as the ItemsPanelTemplate
, and sets the Grid.Column and Grid.Row on the ItemContainerStyle
to position data items in the grid
Is there a way to either add GridLines to the Grid, or to fill in the blank cells with a Border?
Right now I have ShowGridLines
set to True which makes the dotted lines, however I want Horizontal lines to show up, and I'd prefer solid GridLines
There is a rather large amount of XAML, but here's a screenshot of how my XAML is laid out:
回答1:
Sorry, styling the grid lines can't be done. Atleast not in an easy way. See the following question for an explanation: How can I change the color of the gridlines of a Grid in WPF?
MSDN docs say "Only dotted lines are available because this property is intended as a design tool to debug layout problems and is not intended for use in production quality code. If you want lines inside a Grid, style the elements within the Grid to have borders."
Edit: See the following link: Change Color / Thickness of Grid Lines for WPF Grid Control
It's a custom control that derives from Grid
and draws the GridLines
in OnRender
. I Tried it out and it seems to be working great. Useable like this
<controls:GridControl ShowCustomGridLines="True"
GridLineBrush="Red"
GridLineThickness="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</controls:GridControl>
来源:https://stackoverflow.com/questions/7449844/how-can-i-get-a-grid-to-draw-borders-for-blank-cells