Silverlight:无法让 ScrollViewer 和 WrapPanel 一起工作
我正在使用 WrapPanel 来格式化一些文本。 在运行时,我将 TextBlock 和 StackPanel 添加为子项。 显然我需要一个滚动条,具体取决于数据大小。 在网上搜索时,我发现了多个答案,它们都建议在 WrapPanel 周围放置一个 ScrollViewer。 这对我来说很有意义,但我无法让它发挥作用。 这是我的代码:
scrollView = new ScrollViewer();
scrollView.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollView.HorizontalAlignment = HorizontalAlignment.Stretch;
scrollView.VerticalAlignment = VerticalAlignment.Stretch;
scrollView.Margin = new Thickness(0);
scrollView.BorderThickness = new Thickness(0);
textPanel = new WrapPanel();
textPanel.Width = Width;
scrollView.Content = textPanel;
那不起作用。 ScrollViewer 似乎随着包含的 WrapPanel 一起增长。 如果我将垂直滚动条设置为可见,我可以看到滚动条随着内容而增长。 但是 ScrollViewer 从包含的窗口中增长出来,因此永远不会显示滚动条。
有什么提示我可能做错了什么吗?
干杯, 阿希姆
I'm using a WrapPanel to format some text. During runtime I add TextBlocks and StackPanels as Children. Obviously I need a scrollbar depending on the data size. Searching the web I found multiple answers which all propose to put a ScrollViewer around the WrapPanel. That makes sense to me, but I cannot get it to work. Here's my code:
scrollView = new ScrollViewer();
scrollView.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollView.HorizontalAlignment = HorizontalAlignment.Stretch;
scrollView.VerticalAlignment = VerticalAlignment.Stretch;
scrollView.Margin = new Thickness(0);
scrollView.BorderThickness = new Thickness(0);
textPanel = new WrapPanel();
textPanel.Width = Width;
scrollView.Content = textPanel;
That does not work. The ScrollViewer seems to grow with the contained WrapPanel. If I set the vertical scroll bar to visible, I can see that the scrollbar grows with the content. But the ScrollViewer grows out of the containing window and therefor no scrollbar is displayed ever.
Any hint what I might be doing wrong?
cheers,
Achim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一些东西来限制 WrapPanel 和 ScrollViewer 的大小 - 您可以设置查看器的宽度和高度,然后在 WrapPanel 上使用元素绑定:
希望有帮助。
伊恩
You need something to contrain the size of the WrapPanel and the ScrollViewer - you could set the width and height of the viewer then use an element binding on the wrappanel:
Hope that helps.
Ian