3

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

这是我的代码:

<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>
4

2 回答 2

0

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

于 2012-04-25T13:24:40.760 回答
0

要解决此问题,请尝试在嵌套列表框中设置属性 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>
于 2012-04-27T11:40:50.220 回答