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.
Unfortunately, activation email could not send to your email. Please try again.

Disable scrollviewer if there's no scroll because of not enough items and enable it if there are

Thread ID:

Created:

Updated:

Platform:

Replies:

132144 Aug 16,2017 09:11 AM Aug 19,2017 07:56 AM UWP 2
loading
Tags: SfDataGrid
Alexandru Pastor Opris
Asked On August 16, 2017 09:11 AM

Hello,

We've been trying to see if it's possible to have an event or any way to have the scrollviewer disabled when there are not enough items for a scroll and have it enabled once there are. This would avoid a small issue which is that when the datagrid doesn't have enough items it shouldn't catch the scroll event and avoid scrolling on the parent element.

I've created a little sample having a scrollviewer and a list of textblock which exceed the screen on vertical for the scrollviewer to be enabled. If there are a few items in the datagrid and there's no scroll it just catched and disables the parent's scrollviewer, is there any solution to this? One solution would be by adding the properties ScrollViewer.HorizontalScrollMode="Disabled" and ScrollViewer.VerticalScrollMode="Disabled" but that would mean that if there are a lot of items the scroll on the datagrid won't work at all.

Also created a little video to show it.


Have a nice day,
Alexandru.

Attachment: SfDataGrid_ScrollViewer_a77dff0b.zip

Gnanasownthari Thirugnanam [Syncfusion]
Replied On August 17, 2017 10:56 AM

Hi Alexandru, 

We have analyzed your query “Few items in SfDataGrid while scroll over the SfDataGrid, ScrollViewer does not scrolled”, Scroll over the SfDataGrid while loaded inside the ScrollViewer manipulation handled by itself(SfDataGrid), so ScrollViewer does not scrolled but you can achieve your requirement by disable the ScrollViewer based on ExtentHeight and ExtentWidth of VisualContainer as like below cod example. 

C# 
this.DataGrid1.Loaded += DataGrid1_Loaded; 
private void DataGrid1_Loaded(object sender, RoutedEventArgs e) 
{ 
    VisualContainer visualContiner1 = this.DataGrid1.GetVisualContainer(); 
    //checking the DataGrid height and VisualContiner ExtendedWidth (Total number of Row height) 
    if (this.DataGrid1.ActualHeight > visualContiner1.ExtentHeight)             
        visualContiner1.ScrollOwner.VerticalScrollMode = ScrollMode.Disabled;                 
    if (this.DataGrid1.ActualWidth > visualContiner1.ExtentWidth)             
        visualContiner1.ScrollOwner.HorizontalScrollMode = ScrollMode.Disabled; 
} 

We have modified the sample based on your requirement, you can download the same from below mentioned location. 

Sample location: 

Regards, 
Gnanasownthari T. 
 


Gnanasownthari Thirugnanam [Syncfusion]
Replied On August 19, 2017 07:56 AM

Hi Alexandru,  

You can also achieve your requirement “Few items in SfDataGrid while scroll over the SfDataGrid, ScrollViewer does not scrolled” in another way using IsVerticalRailEnabled and IsVerticalScrollChainingEnabled  attached properties as true like below code example.  

IsVerticalChainingEnabled attached property decides whether the scroll chaining is enabled from Child to its parent. 

C#  
<syncfusion:SfDataGrid x:Name="DataGrid1"  
                                       ScrollViewer.IsVerticalRailEnabled="True" 
                                       ScrollViewer.IsVerticalScrollChainingEnabled="True" 
                                       Height="400" 
                                       Margin="0, 0, 12, 0" 
                                       ItemsSource="{x:Bind Fields.TestClassList0, Mode=OneWay}"> 
</syncfusion:SfDataGrid> 
 
We have modified the sample based on your requirement, you can download the same from below mentioned location.  

Sample location:  
Regards,  
Gnanasownthari T 


CONFIRMATION

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.

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.

;