简体   繁体   中英

Windows 8 Metro ListView - can't disable ScrollViewer (C#/XAML)

I have a ScrollViewer that contains a Horizontal StackPanel that contains 2 ListViews.

My goal is to get the 2 ListViews to scroll together. The problem I'm having is that I can't get the built-in ScrollViewers in the ListViews to be disabled...no matter what I do, they continue to scroll independently. I really must be missing something...any help would be appreciated.

Here's my XAML:

<ScrollViewer VerticalScrollBarVisibility="Visible" 
          HorizontalScrollBarVisibility="Disabled" 
          ZoomMode="Disabled" 
          HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          Width="830" 
          Height="500">

  <StackPanel x:Name="teesSP" 
              HorizontalAlignment="Left" 
              Height="500" 
              Width="830" 
              Orientation="Horizontal" 
              VerticalAlignment="Top">

      <ListView x:Name="timesLV1" 
                HorizontalAlignment="Left" 
                Width="130" 
                Height="500" 
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.HorizontalScrollMode="Disabled"
                ScrollViewer.IsHorizontalRailEnabled="False"
                ScrollViewer.IsHorizontalScrollChainingEnabled="False"
                ScrollViewer.IsScrollInertiaEnabled="False"
                ScrollViewer.IsVerticalRailEnabled="False"
                ScrollViewer.IsVerticalScrollChainingEnabled="False"
                ScrollViewer.IsZoomChainingEnabled="False"
                ScrollViewer.IsZoomInertiaEnabled="False"
                ScrollViewer.VerticalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollMode="Disabled"
                BorderThickness="2" 
                BorderBrush="Black" 
                VerticalAlignment="Top" 
                ItemTemplate="{StaticResource TimeTileTemplate}"
                SelectionMode="Single" 
                SelectionChanged="timesLV_Click" />

      <ListView x:Name="timesLV2" 
                HorizontalAlignment="Left" 
                Width="700" 
                Height="500" 
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                ScrollViewer.HorizontalScrollMode="Disabled"
                ScrollViewer.IsHorizontalRailEnabled="False"
                ScrollViewer.IsHorizontalScrollChainingEnabled="False"
                ScrollViewer.IsScrollInertiaEnabled="False"
                ScrollViewer.IsVerticalRailEnabled="False"
                ScrollViewer.IsVerticalScrollChainingEnabled="False"
                ScrollViewer.IsZoomChainingEnabled="False"
                ScrollViewer.IsZoomInertiaEnabled="False"
                ScrollViewer.VerticalScrollBarVisibility="Disabled"
                ScrollViewer.VerticalScrollMode="Disabled"
                BorderThickness="2" 
                BorderBrush="Black" 
                VerticalAlignment="Top" 
                ItemTemplate="{StaticResource TimeTileTemplate}"
                SelectionMode="Single" 
                SelectionChanged="timesLV_Click" />

  </StackPanel>

</ScrollViewer>

It's because you are specifying a certain width and height for each ListView. Remove the width and height from the ListView and StackPanel and only have it for the scrollviewer.

Then you simply either make the ScrollViewer have a fixed height or the size of the grid in which it is contained in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM