0

I am trying to scroll a scrollviewer to a specific position.

But the scrollviewer is stoping after scrolling to a specific position.

xaml:

<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="0.01*"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Stackpanel Grid.row=0------/>

<ScrollViewer Name="DataList" Grid.Row="2" Grid.RowSpan="2" Grid.Column="1">

    <Grid Name="ScrollContent" Margin="0,0,0,0" Height="1000">
      <Grid.RowDefinitions>
         <RowDefinition Height="1.5*"/>
         <RowDefinition Height="1.5*"/>
      </Grid.RowDefinitions>
     <ScrollViewer Grid.Row="0" Grid.Column="0" Name="DataViewer1" VerticalScrollBarVisibility="Visible">
      -----//code
   </ScrollViewer>
     <Grid Grid.Row="1" Grid.Column="0" Name="DataViewer" >
      ----//code
     </Grid>

   </Grid>
 </Scrollviewer>
</Grid>

I am using the below line:

   DataList.ScrollToVerticalOffset(500);

The behaviour is same when i change the above line to

  DataList.ScrollToVerticalOffset(1000);

Please Help!

Mars
  • 269
  • 1
  • 3
  • 22
  • https://stackoverflow.com/questions/48873610/scrollviewer-not-scrolling-when-height-set-to-auto-or-verticalalignment-set-to-s/48876009#48876009 – André B Jun 06 '18 at 09:31

1 Answers1

0

Give this a try:

<Grid>
    <ScrollViewer Name="DataList">
        <Grid Height="1000" />
    </ScrollViewer>
<Grid>

The scroll viewer will scroll just like you want it to because the height and the width of the scroll viewer are inherited by the height and the width of its container, the grid. And because a grid constraints itself to the size of the window.

I hope this helps!

Dungeon
  • 972
  • 2
  • 16
  • 32
  • Th above solution is working when I set Height="1000"..But If I am setting **Height="*"** its not working.Any idea how to resolve this? – Mars Jun 06 '18 at 07:33
  • In a WPF Grid, `Width="*"` or `Height="*"` means proportional sizing. Visit this link for clear understanding:https://stackoverflow.com/questions/1768293/what-does-the-wpf-star-do-width-100 – Dungeon Jun 06 '18 at 08:26