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

The Archive Base Latest Questions

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

I have a data grid: <DataGrid x:Name=Foo … /> I’d like to bind an

  • 0

I have a data grid:

<DataGrid x:Name="Foo" ... />

I’d like to bind an element’s height to the height of the data grid. Simply doing {Binding ElementName=Foo, Path=ActualHeight} will not work, because it takes the ScrollViewer‘s height, not the total height of the data grid’s contents.

  • 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-06T04:31:13+00:00Added an answer on June 6, 2026 at 4:31 am

    You need to find the DataGrid’s internal ScrollViewer, and bind to it’s ViewportHeight

    Depending on what you’re doing with this value and where you need it, this can be done in a variety of ways.

    Typically this sort of thing is needed for a View-Only purpose, so I would put the code to find the ViewPort height in the CodeBehind

    For example, using some VisualTreeHelpers, you could do something like this:

    // Find first child of type ScrollViewer in object Foo
    var scrollViewer = VisualTreeHelpers.FindChild<ScrollViewer>(Foo);
    
    // If object is found, set other control's height to ViewportHeight
    if (scrollViewer != null)
    {
        MyControl.Height = scrollViewer.ViewportHeight;
    }
    

    I can’t remember if there’s more than one ScrollViewer in a DataGrid… you’d have to use something like Snoop to find out for sure. If there is, there’s an overload of .FindChild() to find an element by name that you should be able to use. The name can be obtained through something like Snoop too.

    This could also be done in a Converter, where you pass the DataGrid to a Converter, and have it find the ScrollViewer and ViewportHeight in the Converter

    <Grid Height="{Binding ElementName=Foo, 
                           Converter={StaticResource GetDataGridContentHeight}}" />
    

    Edit

    I actually did a few tests, and the DataGrid’s ScrollViewer treats sizes a bit differently, probably due to Virtualization. It appears to use relative sizes based on the number of rows.

    The test DataGrid I was working with had 23 rows. The ScrollViewer.ExtentHeight was equal to 23, and ScrollViewer.ViewportHeight was 3, meaning there were 23 rows total, and 3 complete rows were being shown. The ScrollViewer.ScrollableHeight was equal to 20, meaning I could scroll from 0 to 20 (since 3 items are shown, it doesn’t need to go to 23), and the ScrollViewer.VerticalOffset was set to whatever item I was currently scrolled to.

    So to get the actual content height of items in a virtualized ScrollViewer, I think you’re going to have to get the ActualHeight of one of the visible rows, and multiply it by the ScrollViewer.ExtentHeight to get the actual size of your content. This will only work if the Height of all your items is the same though.

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

Sidebar

Related Questions

I have a datagrid with master detail implementation as follows: <data:DataGrid x:Name=dgData Width=600 ItemsSource={Binding
I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
Is it possible to have something like Data Grid or Grid View control in
I have a DataGrid with data populated from an XML binding. I want to
I have a DataGrid table with columns name , phone . In column name
I have a datagrid called DataGridView1, column A contains a name, column B contains
I have a DataGrid in WPF app with several columns, including a Name column.
I have a Data grid with DatagridComboBoxColumn , and i want to Fire Event
We have a data grid to display member records for our clients. We recently
I am a beginner to WPF . I have a data grid for showing

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.