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 7401405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:27:38+00:00 2026-05-29T04:27:38+00:00

I have wrote some code in order to add 100 x 100 cells to

  • 0

I have wrote some code in order to add 100 x 100 cells to a grid. The thing is that I would like to highlight the lines that split the rows/column of the grid.

What properties should I use, or how should I do that?

Bellow is the code for creating the grid cells :

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        for (int i = 0; i < 100 ; i++)

            layoutGrid.RowDefinitions.Add( new RowDefinition {  } );
        for (int i = 0; i < 100; i++)
            layoutGrid.ColumnDefinitions.Add(new ColumnDefinition { });

    }
}
  • 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-29T04:27:38+00:00Added an answer on May 29, 2026 at 4:27 am

    There’s a couple ways you can try. If you take a look at Grid.cs, see the Brushes.Blue & Brushes.Yellow solid colors that make up the dashes you see when you enable ShowGridLines=”True” in the source below? You can set those over to a different color (make them both the same color to not have to edit it much like Brushes.Gray, or you can omit the dash, draw a single line, and could even use a custom brush resource like a gradient.

     /// <summary>
        /// Helper to render grid lines. 
        /// </summary>
        internal class GridLinesRenderer : DrawingVisual 
        { 
            /// <summary>
            /// Static initialization 
            /// </summary>
            static GridLinesRenderer()
            {
                s_oddDashPen = new Pen(Brushes.Blue, c_penWidth); 
                DoubleCollection oddDashArray = new DoubleCollection();
                oddDashArray.Add(c_dashLength); 
                oddDashArray.Add(c_dashLength); 
                s_oddDashPen.DashStyle = new DashStyle(oddDashArray, 0);
                s_oddDashPen.DashCap = PenLineCap.Flat; 
                s_oddDashPen.Freeze();
    
                s_evenDashPen = new Pen(Brushes.Yellow, c_penWidth);
                DoubleCollection evenDashArray = new DoubleCollection(); 
                evenDashArray.Add(c_dashLength);
                evenDashArray.Add(c_dashLength); 
                s_evenDashPen.DashStyle = new DashStyle(evenDashArray, c_dashLength); 
                s_evenDashPen.DashCap = PenLineCap.Flat;
                s_evenDashPen.Freeze(); 
            }
    

    Or there’s a trick you can do shown in XAML (because I had already slapped an example together for a past post elsewhere) where you take a border control with a set BorderBrush & BorderThickness and span incremental borders across the cells & columns like this example;

    <Border Height="300" Width="300" Background="White" BorderThickness="1" BorderBrush="Gray">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>               
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>               
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>               
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>
                <!-- Horizontal Accent Lines -->
                <Border Grid.ColumnSpan="10" BorderThickness="0,1" BorderBrush="Gray"/>
                <Border Grid.Row="2" Grid.ColumnSpan="10" BorderThickness="0,1" BorderBrush="Gray"/>
                <Border Grid.Row="4" Grid.ColumnSpan="10" BorderThickness="0,1" BorderBrush="Gray"/>
                <Border Grid.Row="6" Grid.ColumnSpan="10" BorderThickness="0,1" BorderBrush="Gray"/>
                <Border Grid.Row="8" Grid.ColumnSpan="10" BorderThickness="0,1" BorderBrush="Gray"/>
                <!-- Vertical Accent Lines -->
                <Border Grid.Column="1" Grid.RowSpan="10" BorderThickness="1,0" BorderBrush="Gray"/>
                <Border Grid.Column="3" Grid.RowSpan="10" BorderThickness="1,0" BorderBrush="Gray"/>
                <Border Grid.Column="5" Grid.RowSpan="10" BorderThickness="1,0" BorderBrush="Gray"/>
                <Border Grid.Column="7" Grid.RowSpan="10" BorderThickness="1,0" BorderBrush="Gray"/>
                <Border Grid.Column="9" Grid.RowSpan="10" BorderThickness="1,0" BorderBrush="Gray"/>
                <!-- Content Elements -->
                <TextBlock Text="1" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <TextBlock Text="2" Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <TextBlock Text="3" Grid.Row="2" Grid.Column="9" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <TextBlock Text="4" Grid.Row="4" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                <TextBlock Text="5" Grid.Row="8" Grid.Column="7" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
            </Border>
    

    Or with XAML for DataGrid;

       <Window.Resources>
           <SolidColorBrush x:Key="RedGridLine" Color="#FFFF4444" />
           <SolidColorBrush x:Key="BlueGridLine" Color="#554444FF"/>
        </Window.Resources>
    
        <my:DataGrid VerticalGridLinesBrush="{StaticResource RedGridLine}"
                HorizontalGridLinesBrush="{StaticResource BlueGridLine}" >
    

    Hope this helps and best of luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to write a function that would have some optional code to be
I have a quad core machine and would like to write some code to
I'd like to write some code that would take a given data frame, check
I'm trying to write some LINQ To SQL code that would generate SQL like
I have a class that contains some private attributes. What I would like to
I have been refactoring throwaway code which I wrote some years ago in a
So far I have managed to write some code that should print the source
I have a mobile platform that I am trying to write some communications code
I have a page that at run time I add some control based on
I wrote some code to get the files in a directory. In order to

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.