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

  • Home
  • SEARCH
  • 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 6734465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:53:31+00:00 2026-05-26T10:53:31+00:00

The WPF DataGrid class (Not the Windows Forms DataGrid!) can be set up to

  • 0

The WPF DataGrid class (Not the Windows Forms DataGrid!) can be set up to automatically handle scrolling without an external ScrollViewer and it’s possible to register an event handler for the control’s internal scrollbar by writing XAML like such:

<DataGrid ScrollViewer.ScrollChanged="dGrid_ScrollChanged"  />

Correct me if I’m wrong but in this case, the internal ScrollViewer appears to be some kind of undocumented attached property. ScrollViewer is not a public field of DataGrid and you will find no reference to either ScrollViewer or the ScrollChanged event in the DataGrid documentation. In other words simply doing myDataGrid.ScrollViewer.ScrollChanged += dGrid_ScrollChanged doesn’t work.

So my question is, how does one go about adding or removing an event handler for this ScrollChanged event at runtime? I’m trying to understand what’s going on here as much as I’m trying to solve the problem so the more explanation the better.

  • 1 1 Answer
  • 1 View
  • 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-26T10:53:31+00:00Added an answer on May 26, 2026 at 10:53 am

    Try using UIElement’s AddHandler and RemoveHandler like this in your code behind –

    dg.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(dg_ScrollChanged));
    dg.RemoveHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler(dg_ScrollChanged));
    

    Since ScrollViewer is not a Dependency Property of your dataGrid, you need to hook using AddHandler. Just like you can’t set Grid.RowSpan simply like this dg.Grid.RowSpan = 2
    You have to set Attach Properties like dg.SetValue(Grid.RowSpanProperty, 2)
    Same goes with events you need to hook for attached properties.

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

Sidebar

Related Questions

Can I use the WPF DataGrid control in the same way I use a
I would like to add excel spreadsheet functionality to the WPF toolkit datagrid, can
Our WPF DataGrid does not update its groups when we edit items. We group
How can i stop a WPF DataGrid form automatic display an element binded to
I'm using the WPF DataGrid to bind to a collection of a custom class.
This walkthrough says you can create a WPF datagrid in one line but doesn't
I have a strange problem with a WPF DataGrid from WPF Toolkit. The scrollbars
I am trying to synchronize the horizontal scroll position of 2 WPF DataGrid controls.
I've retemplated the DataGridRow in the Microsoft WPF DataGrid to the below, the problem
What do I need to do to get my WPF DataGrid control to bind

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.