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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:31:54+00:00 2026-06-06T12:31:54+00:00

How can we set border and background color in the WPF grid control ,

  • 0

How can we set border and background color in the WPF grid control ,
i am creating rows and column dynamically and adding then to grid,
can we set color and border from the code behind?

  • 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-06-06T12:31:56+00:00Added an answer on June 6, 2026 at 12:31 pm

    The Background color can just be set for the entire Grid by using the Background property:

    <Grid Background="Red" />
    

    Or if you want it set for individual cells, you need to add an element to the cell that has its Background property set.

    As for Borders, a Grid only contains the ShowGridLines property, which can be used to show thin dotted lines that cannot be styled.

    Per MSDN:

    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.

    So in order to add borders to your Grid, you have to add Border elements or controls that contain a Border to the Grid cells, and style those elements.

    But there is an alternative. This blog post outlines how you can extend the Grid class to create a custom Grid that has properties for Grid lines. I’ve used it successfully in the past when I wanted to render grid lines, but didn’t want to fill every cell with an object.

    <my:CustomGrid ShowCustomGridLines="True"
                   GridLineBrush="Blue"
                   GridLineThickness="1">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I set label's border which is dynamically generated (Not from Interface Builder)?
border:3px solid black; In the above example, you can set color by saying the
How can I set the background color for a part of the background like
Essentially I want a border-less, black window which I can set the location and
You can set the Vim color scheme by issuing :colorscheme SCHEME_NAME but, oddly enough,
How to change background color of GtkTextView? I tried with normal widget set bg
I want to set the background color of JButton. For that I use setBackground()
I have this class .box { background-color:#fff; border:3px solid #eee; } My question is
I want to have a table border (which I can set using css, rather
I want to extract the background from this CSS and then use it 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.