WP7 ScrollViewer 根本不工作
我的意图很简单。创建一种面板,用户可以在其中滚动浏览该特定面板中的许多控件。该面板内的控件可以是按钮、图像或标签……等等。
问题是...如果我将 ScrollViewer 设为垂直,它会滚动,但不会显示其内部的所有控件,而且,它不会停留在我滚动的位置。如果我让它水平,这就是我想要的,它根本不会滚动......一点也不滚动。
以下是我的代码:请帮忙!
<ScrollViewer Height="118" Name="scrollerButtons" Width="362" Canvas.Left="167" Canvas.Top="275" VerticalAlignment="Center">
<StackPanel Height="97" Name="stackPanelButtons" Width="168" Orientation="Horizontal" Canvas.Left="162" Canvas.Top="43" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Width="60" Height="60"> </Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
</StackPanel>
</ScrollViewer>
我添加了一堆按钮只是为了测试整个事情。非常感谢任何帮助。谢谢。
My intention is simple. Create a sort-of panel where the user can scroll through the many controls within that specific panel. The controls within that panel may be buttons, or images, or labels..whatever.
Thing is... If I make my ScrollViewer Vertical, it scrolls but it doesn't show all of the controls within itself, AND, it doesn't stay at the point where I scrolled it. And if I make it horizontal, which is how I want it to be, it doesn't scroll at all... Not one bit.
Below is my code: PLEASE HELP!
<ScrollViewer Height="118" Name="scrollerButtons" Width="362" Canvas.Left="167" Canvas.Top="275" VerticalAlignment="Center">
<StackPanel Height="97" Name="stackPanelButtons" Width="168" Orientation="Horizontal" Canvas.Left="162" Canvas.Top="43" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Width="60" Height="60"> </Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
<Button Width="60" Height="60"></Button>
</StackPanel>
</ScrollViewer>
I have added a bunch of buttons just to test the whole thing. Any help is HIGHLY appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我所做的是监听包含堆栈面板的网格上的 SizeChangedEvent,然后相应地调整 ScrollViewer 的高度。例如,在这里我只是将其设置为屏幕尺寸的一半。它并不完美,但它有效。
What I did was listen to the SizeChangedEvent on a grid that contains the stack panel and then adjusted the height of the ScrollViewer accordingly. Here, for example I just make it half of the screen size. It is not perfect but it works.
从 StackPanel 中删除
Height
属性。您正在强制内部 StackPanel 截断其内容。由于内部 StackPanel (97) 比 ScrollViewer (118) 小,因此 ScrollViewer 无法滚动。 ScrollViewer 期望其内容比 ScrollViewer 本身大。Remove the
Height
attribute from the StackPanel. You are forcing the inner StackPanel to truncate its content. Since the inner StackPanel is smaller (97) than the ScrollViewer (118), there is nothing for the ScrollViewer to scroll. The ScrollViewer expects its content to be larger than the ScrollViewer itself.