5
我在使水平堆栈面板从scrollviewer内滚动时遇到问题。我想要做的是比我的例子更复杂,但是在删除变量之后,我认为如果我能解决最后一个问题,我可以把所有东西都弄清楚。XAML水平堆栈面板滚动
基本上,我不能让scrollviewer水平滚动时,它包含一个水平的stackpanel。
下面是示例XAML:
<ScrollViewer>
<StackPanel Orientation="Horizontal">
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
<Image Source="test.png" Width="400" Height="400"/>
</StackPanel>
</ScrollViewer>
奇怪的是,如果我只是换了方向,从水平到垂直,它滚动就好了。我已经阅读过多篇文章,表示stackpanels有问题,可能会使它们不适合scrollviewers,所以我尝试了一个网格,但获得相同的结果。
<ScrollViewer>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="400"/>
</Grid.ColumnDefinitions>
<Image Source="test.png" Width="400" Height="400" Grid.Column="0"/>
<Image Source="test.png" Width="400" Height="400" Grid.Column="1"/>
<Image Source="test.png" Width="400" Height="400" Grid.Column="2"/>
<Image Source="test.png" Width="400" Height="400" Grid.Column="3"/>
<Image Source="test.png" Width="400" Height="400" Grid.Column="4"/>
<Image Source="test.png" Width="400" Height="400" Grid.Column="5"/>
</Grid>
</ScrollViewer>
看起来很简单,我觉得我误解了一些基本的东西。如果有人能帮忙,我会非常感激。
谢谢!我浏览了无数关于HorizontalScrollBarVisibility的帖子,甚至查看了您发布的MSDN链接,但我从来没有意识到滚动工作需要滚动条可见性。 非常感谢,我花了好几天时间。 – Riot9
令人发疯的是,即使启用了“HorizontalScrollMode”,也必须启用“HorizontalScrollBarVisibility”以使基于触摸的滚动工作。 –