We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GetVisualContainer returns null when SfDataGrid is not on first tab

Thread ID:





142622 Feb 12,2019 02:41 PM UTC Feb 13,2019 07:28 AM UTC WPF 1
Tags: SfDataGrid
James Randle
Asked On February 12, 2019 02:41 PM UTC

Please see the attached code.

As the title suggests, sfDataGrid.GetVisualContainer() returns null when the SfDataGrid is not on the first tab.
I need access to the VisualContainer so I can add a handler to the sfDataGrid.GetVisualContainer().ScrollOwner.ScrollChanged event.

It works fine if the SfDataGrid is on the first tab, or more precisely, the tab that is active when the application starts.


Attachment: SFDataGridGetVisualContainer_484da829.zip

Jayaleshwari N [Syncfusion]
Replied On February 13, 2019 07:28 AM UTC

Hi James, 
Thanks for contacting Syncfusion Support.  
We have analyzed your query ”GetVisualContainer returns null when SfDataGrid is not on first tab” and the provided sample from our side. We regret to let you know that you can get the VisualContainer only when the DataGrid is visible.  
However you can resolve this by adding null check before using the GetVisualContainer method. SfDataGrid.Loaded event will again raise when switching to the tab containing the SfDataGrid.  
sfDataGrid.Loaded += SfDataGrid_Loaded; 
private void SfDataGrid_Loaded(object sender, RoutedEventArgs e) 
    if (sfDataGrid.GetVisualContainer() != null) 
        sfDataGrid.GetVisualContainer().ScrollOwner.ScrollChanged += ScrollOwner_ScrollChanged; 
private void ScrollOwner_ScrollChanged(object sender, ScrollChangedEventArgs e) 
We have attached the modified sample for your reference and you can download the same from the following location 
Please let us know if you would require further assistance. 
Jayaleshwari N 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon