我是 xaml 和 wpf 的新手。
我正在尝试从代码隐藏中将一些用户控件插入到容器中。
我在 MSDN 上阅读了这篇博客文章.
我尝试了那里使用的所有方法和其他一些方法,但从未启用滚动条。
我目前坚持使用的代码是:
<DockPanel>
<ScrollViewer HorizontalAlignment="Left" Margin="252,12,0,0">
<ItemsControl Name="captchaControls" Width="339" Height="286">
</ItemsControl>
</ScrollViewer>
</DockPanel>
有谁知道为什么?
编辑:
让它像这样工作:
<DockPanel>
<ScrollViewer HorizontalAlignment="Left" Margin="252,12,0,0" Width="339" Height="286">
<ItemsControl Name="captchaControls">
</ItemsControl>
</ScrollViewer>
</DockPanel>
最佳答案
删除 Width="339" Height="286"
来自 XAML。它会导致 ItemsControl 具有恒定大小,无论其内部是什么。
顺便提一句。您可能应该使用 x:Name
而不是 Name
,谷歌搜索解释原因的文章。
关于wpf - ScrollViewer 滚动条始终禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10626123/