问题
I have a scrollview with a big grid containing two smaller grids. the grids are supposed to scroll together vertically, but only the right grid should scroll horizontally. This is because the information in the left grid is needed as a reference while the right grid can contain 100+ columns.
I have already tried putting the grids in separate scrollviews and linking them with an eventhandler. But I didn't find any code to do this in a Windows 8.1 application.
Is there any way to do this for WinRT apps?
回答1:
You should nest the ScrollViewers
. Something like this:
<Grid
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="Auto"/>
<ColumnDefinition
Width="700"/>
</Grid.ColumnDefinitions>
<StackPanel>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">1</TextBlock>
</StackPanel>
<ScrollViewer
Grid.Column="1"
VerticalScrollBarVisibility="Disabled"
VerticalScrollMode="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalScrollMode="Auto"
ZoomMode="Disabled">
<StackPanel>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
<TextBlock Margin="10,10,50,10" FontSize="24">A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. A very long text. </TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
</ScrollViewer>
</Grid>
来源:https://stackoverflow.com/questions/22812456/linking-only-vertical-offset-of-two-scrollviewers