Patrick McCurley
Patrick McCurley

Reputation: 2064

Nested scrollviewer within a gridviewitem

I have a scenario within WinRT where I have a standard gridview that displays content in a horizontal manner - the usual WinRT scrollviewer kicks in here for content that appears off the right hand side of the screen, so we can 'swipe left' as per many WinRT applications.

My datatemplate for gridviewitems in XAML is as follows:

            <DataTemplate>
                <Grid Background="White" Margin="0,0,1,1">
                    <ScrollViewer Grid.Column="3" Width="200">
                        <ListView Width="600" Height="170" Margin="0" Padding="10" ItemsSource="{Binding Path=ProductListItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding Path=LargeImage}" Width="200" Height="150" Stretch="UniformToFill"/>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </ScrollViewer>
                </Grid>
            </DataTemplate>

As i hope you can see from the source, the templates item is attempting to show images stored within listviewer wrapped in a scrollviewer (approx 3 shown at any time) with any overflowing images being swipable within the scrollviewer.

The problem is that the main parent gridview steals all input, and any swipes (even when placed within the templated listview scrollviewer) are not registered.

Anyone any idea how to overwrite this default behavior and have 2 types of scrolling within my control?

Thanks,

Upvotes: 1

Views: 1195

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

I think the IsHorizontalScrollChainingEnabled property of a ScrollViewer might help you do what you want, but that said - you should never do what you are trying to do since this is a really bad design. Never put GridViews or ListViews inside of a ScrollViewer and never nest any of these in one another. If you want to provide a way to see more content than fits in a GridView - you should allow navigating to another page that would allow you to see it. In your case - you are trying to nest a ListView inside of a ScrollViewer inside of a GridView which basically means you are nesting 3 ScrollViewers in your visual tree, which is double bad.

Upvotes: 1

Related Questions