嵌套ListView滚动问题

时间:2013-05-25 08:08:06

标签: windows-8 microsoft-metro windows-store-apps winrt-xaml

我正在使用WINRT应用程序它有一个嵌套Listviews.I主要Listview滚动有一些问题当我的鼠标点到来时第二个Listview我无法滚动主Listview我禁用第二个Listview“ScrollViewer.VerticalScrollBarVisibility”和“ScrollViewer.VerticalScrollMode”也是如此,但它不起作用。在这里,我附上了我的代码。

<Page.Resources>

    <DataTemplate x:Key="ItemTemplate">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="95*"/>
                <ColumnDefinition Width="5*"/>
            </Grid.ColumnDefinitions>
            <Grid>
                <TextBlock x:Name="txtSlno" Foreground="Black" FontSize="18">
                                <Run Text="{Binding SNLO}"/>
                                <Run Text="."/>
                </TextBlock>
                <TextBlock x:Name="txtItem" Text="{Binding ItemDescription}" FontSize="18" Margin="22,0,0,0" TextWrapping="Wrap" Foreground="Black"/>
            </Grid>

            <ListView x:Name="lstCategory" Grid.Row="1" Margin="30,0,0,0" ItemsSource="{Binding Categories}" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollMode="Disabled" SelectionMode="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <RadioButton Content="{Binding CategoryDescription}" FontSize="16" IsChecked="{Binding IsChecked,Mode=TwoWay}" GroupName="{Binding ItemId}" Foreground="Black" BorderBrush="Black" IsThreeState="False" Style="{StaticResource RadioButtonStyle}"/>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </DataTemplate>
</Page.Resources>

主ListView

<ListView x:Name="lstItem"  ItemsSource="{Binding ItemList,Mode=TwoWay}" ItemTemplate="{StaticResource ItemTemplate}" SelectionMode="None" Margin="0,20,0,13"/>

1 个答案:

答案 0 :(得分:1)

如果您查看ListView控件的默认模板,可以看到它包含一个围绕内部ScrollViewer的{​​{1}}。

ItemsPresenter是吞下鼠标事件的原因,这就是无法滚动外部ListView的原因。

您只需创建一个不包含ScrollViewer的自定义模板,如下所示:

ScrollViewer

将此<Style x:Key="ListViewWithoutScrollViewerStyle" TargetType="ListView"> <Setter Property="IsTabStop" Value="False"/> <Setter Property="TabNavigation" Value="Once"/> <Setter Property="IsSwipeEnabled" Value="True"/> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled"/> <Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False"/> <Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled"/> <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="ItemContainerTransitions"> <Setter.Value> <TransitionCollection> <AddDeleteThemeTransition/> <ContentThemeTransition/> <ReorderThemeTransition/> <EntranceThemeTransition IsStaggeringEnabled="False"/> </TransitionCollection> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="Vertical"/> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListView"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> <!--Commented out the ScrollViewer so it does not swallow the mouse events.--> <!--<ScrollViewer x:Name="ScrollViewer" BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}" HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}" IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}" IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" TabNavigation="{TemplateBinding TabNavigation}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}">--> <ItemsPresenter HeaderTemplate="{TemplateBinding HeaderTemplate}" Header="{TemplateBinding Header}" HeaderTransitions="{TemplateBinding HeaderTransitions}" Padding="{TemplateBinding Padding}"/> <!--</ScrollViewer>--> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> 应用于内部Style会使滚动工作适用于外部ListView