Misha Zaslavsky
Misha Zaslavsky

Reputation: 9646

winrt-xaml how to scroll over the content of a stackpanel?

I have a scroller and when I stand on it, it scrolls well, but if I stand over the content inside the stackpanel (which is wrapped with a scrollviewer), the scroller does not work, why?

<ScrollViewer Grid.Column="0" VerticalScrollMode="Enabled" VerticalScrollBarVisibility="Auto">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="Participants" />
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <TextBlock Text="{Binding Path=Users.Count}" />
            <TextBlock Text="/" />
            <TextBlock Text="{Binding MaxParticipants}" />
        </StackPanel>
        <ListView ItemsSource="{Binding Users}" Tapped="User_Tapped">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ListViewItem IsHitTestVisible="False">
                        <StackPanel>
                            <facebookControls:ProfilePicture ProfileId="{Binding FacebookId}" />
                            <TextBlock Text="{Binding UserName}" />
                        </StackPanel>
                    </ListViewItem>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackPanel>
</ScrollViewer>

Upvotes: 1

Views: 716

Answers (1)

Benoit Catherinet
Benoit Catherinet

Reputation: 3345

The problem is that the ListView has it own Scroll viewer so when you scroll over the ListView, the ListView scroll viewer get the scroll events.
If you don't need items selection, then the easiest is to just replace ListView by ItemsControl.
If you need item selection, then you can just remove the ScrollViewer from the Style of the ListView. Here is a ListView style without scrollviewer:

<Style x:Key="ListViewStyle1" TargetType="ListView">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListView">
                <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>

Also if you use ListView you should not use Tapped="User_Tapped" to get the event when a User is Tapped, instead you should set IsItemClickEnabled="True" and use the ItemClicked event

Upvotes: 2

Related Questions