Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:35:24+00:00 2026-05-25T17:35:24+00:00

I have an ItemsControl which uses a Grid as the ItemsPanelTemplate , and sets

  • 0

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

Screenshot

There is a rather large amount of XAML, but here’s a screenshot of how my XAML is laid out:
XAML Layout

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:35:24+00:00Added an answer on May 25, 2026 at 5:35 pm

    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: If you want the borders you can create a custom Grid and draw the GridLines in OnRender method of the control.

        using System.Windows;
        using System.Windows.Controls;
        using System.Windows.Media;
    
        namespace BorderGridControl
        {
            public class GridControl : Grid
            {
                #region Properties
                public bool ShowCustomGridLines
                {
                    get { return (bool)GetValue(ShowCustomGridLinesProperty); }
                    set { SetValue(ShowCustomGridLinesProperty, value); }
                }
    
                public static readonly DependencyProperty ShowCustomGridLinesProperty =
                    DependencyProperty.Register("ShowCustomGridLines", typeof(bool), typeof(GridControl), new UIPropertyMetadata(false));
    
                
                public Brush GridLineBrush
                {
                    get { return (Brush)GetValue(GridLineBrushProperty); }
                    set { SetValue(GridLineBrushProperty, value); }
                }
    
                public static readonly DependencyProperty GridLineBrushProperty =
                    DependencyProperty.Register("GridLineBrush", typeof(Brush), typeof(GridControl), new UIPropertyMetadata(Brushes.Black));
    
                public double GridLineThickness
                {
                    get { return (double)GetValue(GridLineThicknessProperty); }
                    set { SetValue(GridLineThicknessProperty, value); }
                }
    
                public static readonly DependencyProperty GridLineThicknessProperty =
                    DependencyProperty.Register("GridLineThickness", typeof(double), typeof(GridControl), new UIPropertyMetadata(1.0));
                #endregion
    
                protected override void OnRender(DrawingContext dc)
                {
                    if (ShowCustomGridLines)
                    {
                        foreach (var rowDefinition in RowDefinitions)
                        {
                            dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(0, rowDefinition.Offset), new Point(ActualWidth, rowDefinition.Offset));
                        }
    
                        foreach (var columnDefinition in ColumnDefinitions)
                        {
                            dc.DrawLine(new Pen(GridLineBrush, GridLineThickness), new Point(columnDefinition.Offset, 0), new Point(columnDefinition.Offset, ActualHeight));
                        }
                        dc.DrawRectangle(Brushes.Transparent, new Pen(GridLineBrush, GridLineThickness), new Rect(0, 0, ActualWidth, ActualHeight));
                    }
                    base.OnRender(dc);
                }
                static GridControl()
                {
                    DefaultStyleKeyProperty.OverrideMetadata(typeof(GridControl), new FrameworkPropertyMetadata(typeof(GridControl)));
                }
            }
        }
    

    I Tried it out and it seems to be working great.

    Here an example of using:

        <controls:GridControl ShowCustomGridLines="True"
                              GridLineBrush="Red"
                              GridLineThickness="1">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
        </controls:GridControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ItemsControl that uses a DataTemplate. The DataTemplate contains a TextBox, which
I have an ItemsControl which has a Canvas as it's ItemsPanel, the items are
Suppose we have an ItemsControl, which is bounded to a source. Is there any
I have a ItemsControl which displays its items in a ScrollViewer , and does
I want to have an ItemsControl in which the items are displayed horizontally .
I have ItemsControl which is bound and creates multiple Polylines, one for each data
I have ItemsControl in which the ItemsPanel is a Canvas. The data template is
I have ItemsControl which I bind to ObservableCollection On my view model I just
I have an ItemsControl which is giving me issues. It has a DataTemplate, which
I'm trying to display a list of Notes. I have an ItemsControl which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.