开发者

vertical scrollbar is not working in WPF

开发者 https://www.devze.com 2023-03-14 00:05 出处:网络
I have a listbox under sta开发者_开发百科ckpanel and vertical scrollbar is visible but the scroller is not coming. The horizontal works fine. I can scroll across the listbox but not vertically.

I have a listbox under sta开发者_开发百科ckpanel 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.


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.


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}"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号