vertical scrollbar is not working in WPF

末鹿安然 提交于 2019-12-25 06:35:03

问题


I have a listbox under stackpanel and vertical scrollbar is visible but the scroller is not coming. The horizontal works fine. I can scroll across the listbox but not vertically.

<ListBox Width="700"  Height="205"  x:Name="log_Enteries"  ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible">
        </ListBox>

I know setting height and width is not wise but it was desperate try I guess.


回答1:


It's in a StackPanel. A vertically-oriented StackPanel will give its children whatever height they ask for, even if it means they run off the screen. Hence, the vertical ScrollBar will never show. Choose the right panel and you'll see the ScrollBar.




回答2:


Use MaxHeight of your ListBox instead
You can also set your MaxHeight to parent StackPanel to achive want you want somthing like this:

MaxHeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=Height}"


来源:https://stackoverflow.com/questions/6379130/vertical-scrollbar-is-not-working-in-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!