1

我正在使用 WINRT 应用程序,它有一个嵌套的 Listviews。当我的鼠标指向第二个 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 x:Name="lstItem"  ItemsSource="{Binding ItemList,Mode=TwoWay}" ItemTemplate="{StaticResource ItemTemplate}" SelectionMode="None" Margin="0,20,0,13"/>
4

1 回答 1

1

如果您查看ListView控件的默认模板,您会发现它包含一个ScrollViewer围绕内部的ItemsPresenter.

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

您可以像这样简单地创建一个不包含 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应该使外部的滚动工作ListView

于 2013-06-04T19:05:28.453 回答