我正在尝试阻止在ListBox中滚动。使用ScrollViewer.VerticalScrollBarVisibility看起来很棒 - 滚动被阻止了......但是!只需点击ListBox的底部,内容就会向下移动。 我试图在duplicated issue之前提出同样的问题(对不起,可能涉及的人)。
这是我的代码:
<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>
答案 0 :(得分:0)
将列表框的垂直对齐属性设置为Top。 虽然不确定,但这可能有所帮助。
答案 1 :(得分: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>