locked
why short swipe is not working for gridview when scrollviewer is removed from it's style template (code included)

    Question

  • tap on item to select is still working, but short swipe is not working. I guess it is caused by short swipe is implemented by handling the event passed to scrollviewer? But it make not too much sense to me for not able to do short swipe without scrollviewer from a SDK user standpoint, can I have more information about this (why, and any workaround?)

    There is a sample code:

    thanks!

    <Page
        x:Class="test_gridview_without_scrollviewer.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:test_gridview_without_scrollviewer"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
        <Page.Resources>
            <ResourceDictionary>
                <Style x:Key="MyGridViewStyle" TargetType="GridView">
                    <Setter Property="Padding" Value="0,0,0,10"/>
                    <Setter Property="IsTabStop" Value="False"/>
                    <Setter Property="TabNavigation" Value="Once"/>
                    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
                    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
                    <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled"/>
                    <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False"/>
                    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled"/>
                    <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False"/>
                    <Setter Property="ScrollViewer.ZoomMode" Value="Disabled"/>
                    <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
                    <Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True"/>
                    <Setter Property="IsSwipeEnabled" Value="True"/>
                    <Setter Property="ItemContainerTransitions">
                        <Setter.Value>
                            <TransitionCollection>
                                <AddDeleteThemeTransition/>
                                <ContentThemeTransition/>
                                <ReorderThemeTransition/>
                                <EntranceThemeTransition IsStaggeringEnabled="False"/>
                            </TransitionCollection>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <WrapGrid Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="GridView">
                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                    <ItemsPresenter HeaderTemplate="{TemplateBinding HeaderTemplate}" Header="{TemplateBinding Header}" HeaderTransitions="{TemplateBinding HeaderTransitions}" Padding="{TemplateBinding Padding}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ResourceDictionary>
        </Page.Resources>
        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <GridView
                Style="{StaticResource MyGridViewStyle}"
                >
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
                <Grid Height="200" Width="200" Background="AliceBlue"/>
            </GridView>
        </Grid>
    </Page>


    • Edited by Helin Wang Tuesday, January 8, 2013 8:15 PM
    Tuesday, January 8, 2013 8:10 PM

All replies

  • The following style still supports swipe:

    <ScrollViewer x:Name="ScrollViewer" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"> <ItemsPresenter ... /> </ScrollViewer>

    ---

    If one now suppresses the "x:Name='ScrollViewer'" attribute, swipe does not work anymore. Conclusion: "ListViewBase.IsSwipeEnabled ItemsControls" seem to search for the x:Name='ScrollViewer' in order to exploit their "listens to gesture recognizer" capability. I guess this is 'Framework baked-in' design. 



    • Edited by ForInfo Wednesday, January 9, 2013 3:47 PM
    Wednesday, January 9, 2013 3:45 PM
  • Hi thanks for the reply.

    <ScrollViewer x:Name="ScrollViewer" VerticalScrollMode="Disabled">
       <ItemsPresenter ... />
    </ScrollViewer>

    Also work, so my conclusion is vertical scroll should be disabled to process vertical swipe. Which make sense to me.

    But what does not make sense to me is if I change the code to:

    <ContentControl x:Name="ScrollViewer">
       <ItemsPresenter ... />
    </ContentControl>

    Short swipe does not work.

    Note: ContentControl is the parent class of ScrollViewer.

    I think the baked in code uses x:Name="ScrollViewer" to receive event for handling. Since I still provide x:Name="ScrollViewer", the short swipe should work, I think short swipe detection should not be implemented based on ScrollViewer. IMHO the implementation is not good enough because it had dependency to some unneeded thing.

    Can you let some related people know this?

    Thanks.

    Wednesday, January 9, 2013 8:31 PM
  • "I think short swipe detection should not be implemented based on ScrollViewer".

    As you know, ItemsControls like GridView, ListView, etc. are originally designed to support an indefinite amount of items. It is therefore natural to centralize all their gesture listening in a ScrollViewer presenter that supports [was designed for] such functionality, even in those cases where a constrained set of items exists as Items or ItemsSource.

    More generally, it is also good object-oriented practice to implement specific functions in classes designed for a specific purpose, and not to push those functions 'up the o-o hierarchy'. 

    Thank you.

    Thursday, January 10, 2013 6:30 AM
  • Hi,

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 14, 2013 2:43 AM