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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:24:43+00:00 2026-05-23T18:24:43+00:00

I am having trouble sizing a WPF control (I’ll use the Grid control in

  • 0

I am having trouble sizing a WPF control (I’ll use the Grid control in this example) to the size of the Client area of a Window. I realize that the Grid automatically fills all available space by default, however I require the Grid‘s Width to be set manually so that I may bind to it from another control (a DataGrid with one of its column’s Width‘s set to Star if it makes any difference).

Please consider the following XAML:

<Window x:Class="TestApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="768" Width="1024"
        x:Name="mainWindow">

    <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Auto">
        <Grid x:Name="testGrid" Background="DarkGray">
        </Grid>
    </ScrollViewer>

</Window>

And the following Code-Behind:

using System.Windows;

namespace TestApplication
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            testGrid.Width = mainWindow.Width - (SystemParameters.BorderWidth * 2);
        }
    }
}

When running this simple application, the Grid has a width that is slightly larger than the Client area of the Window, resulting in a Horizontal Scroll Bar being displayed. If SystemParameters.BorderWidth does not accurately calculate the width of the Window‘s border, what does?

As per the most recent MSDN documentation, SystemParameters.BorderWidth: Gets the metric that determines the border width of the nonclient area of a nonminimized window.

  • 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-23T18:24:43+00:00Added an answer on May 23, 2026 at 6:24 pm

    After having fought with this sizing issue for quite some time, I have finally found an elegant solution to the problem. Though I have alread selected @Rick Sladkey’s response as the answer (and answer my question it did), I thought I might post my updated understanding in hopes that it might help someone else down the line.

    The real frustration point, it turns out, was in dealing with the ScrollViewer. While sizing my content to the ActualWidth of the ScrollViewer worked wonderfully when it’s VerticalScrollBar was not visible, things began to break down as soon as my content grew to a vertically scrollable height. Though I had expected the binding on ActualWidth to resize my contol to fit within the viewable area of the ScrollViewer, in reality it remained the same width and became horizontally scrollable as well.

    As it turns out, the fix was actually quite simple. Rather than binding the height or width of a control to the ActualHeight or ActualWidth of the ScrollViewer (respectively), bind the height or width of the control to the ViewportHeight or ViewportWidth of the ScrollViewer.

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

Sidebar

Related Questions

Im having trouble with this javascript. here is a n example window.onload = initPage;
I've created this simple demo because I'm having some trouble making auto-sizing work in
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =
Having trouble with this -- a couple of other related posts out there, but
having trouble coming up with search parameters for this issue, so I can't find
Having trouble finding a solution for my situation here. Sorry if this has been
Having trouble inheriting from a template class. Looks something like this: template<typename type> class
Having trouble with this..I'm sure I'm missing something simple but I simply want the
Having trouble with the examples for the .RowStart method. Comparing the 2 syntaxes: http://www.jeremyskinner.co.uk/2009/03/01/mvccontrib-grid-part-5-the-action-syntax/

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.