Thomas
Thomas

Reputation: 113

WPF: ScrollViewer with more than one DataGrid and Label

In my WPF-Application I have a window which contains many dynamic DataGrid with a Label on top as the heading line. These Elements are children of an ScrollViewer. If I scroll up or down the ScrollViewer always jump to the Label. From the Content of the DataGrids only the first columns are visible. My WPF-Code:

<ScrollViewer CanContentScroll="True" PanningMode="VerticalFirst" MouseWheel="ResultDataGrid_OnMouseWheel" x:Name="ResultScrollViewer" Height="Auto">
  <StackPanel x:Name="ResultStackPanel">
  <TextBlock Text="Result" Style="{StaticResource Heading2}" />
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Informations" x:Name="LabelInfo" Style="{StaticResource BoldLabel}"/>
       <DataGrid x:Name="ResultMeta" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Statistics" Style="{StaticResource BoldLabel}"/>
       <DataGrid x:Name="ResultStat" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <StackPanel Style="{StaticResource ResultStackPanel}">
       <Label Content="Resources" Style="{StaticResource BoldLabel}" />
       <DataGrid x:Name="ResultResources" Style="{StaticResource DataGridStyle}" />
    </StackPanel>
    <!-- ... -->
  </StackPanel>
</ScrollViewer>

Upvotes: 0

Views: 291

Answers (1)

JPOne
JPOne

Reputation: 216

The default scroll behavior of a ScrollViewer is scrolling elements. You can try to change this behavior to set this to pixel with the option CanContentScroll="bool".

More information can you get from the MSDN

http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.cancontentscroll(v=vs.110).aspx

But remember that this option will force the ScrollViewer to load all available elements and not the elements that are shown (performance on loading).

Upvotes: 1

Related Questions