不足以阻止在 WP7 列表框中滚动

本文关键字:滚动 列表 WP7 不足以 | 更新日期: 2023-09-27 18:32:15

我试图阻止在列表框中滚动。使用ScrollViewer.VerticalScrollBarVisibility看起来像是一个很好的解决方案 - 防止滚动...但!内容向下移动,只需我点击列表框的底部。我试图在重复问题之前询问类似的主题(对不起,它可能与谁有关)。

这是我的代码:

<StackPanel     Orientation="vertical">         
    <Grid Height="130" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Image   Grid.Column="0"  x:Name="itemIco1" Width="120" Height="120" HorizontalAlignment="Left" 
                    Source="{Binding ImageURL}" 
                    Stretch="Fill" CacheMode="BitmapCache" VerticalAlignment="Top" Margin="0,5,5,0" Visibility="Visible"/>  
        <ListBox  Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                </Style>
            </ListBox.ItemContainerStyle>
            <TextBlock   
                        Name="TextBlockTitle" 
                        Margin="0,0,0,0" 
                        FontSize="26" FontFamily="Segoe WP Semilight"  Foreground="{Binding TitleColor}"
                        TextTrimming="WordEllipsis" TextWrapping="Wrap"
                        Width="Auto" Height="auto" MaxHeight="96" VerticalAlignment="Top"  FontWeight="{Binding Font}" Text="{Binding Title}" />
            <TextBlock 
                        Name="TextBlockBody" 
                        Margin="0,0,0,0" 
                        FontSize="26" FontFamily="Segoe WP Semilight" Foreground="#FF5C5A5A" 
                        TextTrimming="WordEllipsis" TextWrapping="Wrap"
                        Width="Auto" Height="auto" MaxHeight="100" VerticalAlignment="Top" Text="{Binding Body}" FontWeight="{Binding Font}"/>              
        </ListBox>      
    </Grid>
    <TextBlock x:Name="date" Height="16" Text="{Binding Date}" TextWrapping="Wrap" Margin="0,0,0,0" FontSize="16" FontFamily="Segoe WP Semilight"  FontWeight="{Binding Font}" Foreground="Black" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>
</StackPanel>

不足以阻止在 WP7 列表框中滚动

要解决此问题,请尝试在嵌套列表框中设置属性IsHitTestVisible="False",因此它应该是这样的:

 <ListBox IsHitTestVisible="False" Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
                                        <ListBox.ItemContainerStyle>
                                            <Style TargetType="ListBoxItem">
                                                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                                            </Style>
                                        </ListBox.ItemContainerStyle>
                                        <TextBlock  x:Name="TextBlockTitle" Margin="0,0,0,0" FontSize="26" FontFamily="Segoe WP Semilight"  Foreground="{Binding TitleColor}" TextTrimming="WordEllipsis" TextWrapping="Wrap" Width="Auto" Height="auto" MaxHeight="96" VerticalAlignment="Top"  FontWeight="{Binding Font}" Text="{Binding NewsTitle}" />
                                        <TextBlock x:Name="TextBlockBody" Margin="0,0,0,0" FontSize="26" FontFamily="Segoe WP Semilight" Foreground="#FF5C5A5A" TextTrimming="WordEllipsis" TextWrapping="Wrap" Width="Auto" Height="auto" MaxHeight="100" VerticalAlignment="Top" Text="{Binding NewsBody}" FontWeight="{Binding Font}"/>
                                    </ListBox>

将列表框的垂直对齐属性设置为"顶部"。虽然不确定,但这可能会有所帮助。