ListView touch input: disable vertical scrolling once Holding event has been raised RRS feed

  • Question

  • Hi,

     I have a scenario where i want to disable vertical scrolling for a listview once the hold event has been raised and re-enable it once the PointerReleased event has fired. 

     <ListView HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                      ItemsSource="{Binding}" x:Name="lstView" Holding="OnHolding" PointerPressed="OnPointerPressed" PointerReleased="OnPointerReleased">
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <VirtualizingStackPanel Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Recycling"/>
                        <Border Height="80" Background="Olive"
                                HorizontalAlignment="Stretch" Margin="2">
                            <Grid Background="{StaticResource gradientBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                    <RowDefinition Height=".4*"/>
                                    <RowDefinition Height=".6*"/>
                                <TextBlock Text="{Binding Title}" FontSize="18" Margin="2" x:Name="txtBlock" Foreground="White" Grid.Row="0"/>
                                <TextBlock x:Name="txtEdit" FontSize="16" Margin="2" TextWrapping="Wrap" TextTrimming="WordEllipsis" Foreground="White"
                                         Text="{Binding Description}" Grid.Row="1" />

    On the Holding event handler i have set the VirtualizingStackPanel::CanVerticallyScroll and also the ScrollViewer::VerticalScrollMode to None but none of these have any effect.

       private void OnHolding(object sender, Windows.UI.Xaml.Input.HoldingRoutedEventArgs e)
                if (e.HoldingState == Windows.UI.Input.HoldingState.Started)
                    var element = e.OriginalSource as FrameworkElement;
                    var item = element.GetParent<ListViewItem>();
                    if (item != null)
                        Debug.WriteLine("ListView holding...");
                        _item = item;
                        var transform = _item.RenderTransform as TranslateTransform;
                        if (transform == null)
                            transform = new TranslateTransform() { X = 10 };
                            _item.RenderTransform = transform;
                        _isHolding = true;
                        _scrollViewer.VerticalScrollMode = ScrollMode.Disabled;
                        _panel.CanVerticallyScroll = false;
                        e.Handled = true;

    It would have been great to be able to inherit the VirtualizingStackPanel but the class has been sealed. Any help would be much appreciated.


    Tuesday, August 14, 2012 4:15 PM


  • An interesting and by-design effect someone else reported as a bug might help you here.  If you put the listview inside a grid with a width set only as much as it needs to allow you to scroll, and then change the width to star width, it will disable scrolling.  Please see this post:


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, August 15, 2012 2:30 PM