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

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

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

2 Replies

GT Gnanasownthari Thirugnanam Syncfusion Team August 17, 2017 02:56 PM UTC

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. 
 



GT Gnanasownthari Thirugnanam Syncfusion Team August 19, 2017 11:56 AM UTC

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 


Loader.
Live Chat Icon For mobile
Up arrow icon