[英]ListBox Vertical Scrollbar does not show up (WPF)
I have a view that should display information and to test it I added testdata. 我有一个视图,该视图应显示信息并进行测试,我添加了testdata。 However if I add too much items for screen space the vertical scroll bar does not appear. 但是,如果我为屏幕空间添加了太多项目,则不会出现垂直滚动条。
This is my XML Code: 这是我的XML代码:
<UserControl x:Class="not relevant"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="not relevant"
mc:Ignorable="d"
Width="250">
<Border Background="{DynamicResource BG}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1">
<StackPanel>
<Grid>
<Label Height="30" Content="Geöffnete Designs" HorizontalContentAlignment="Center"></Label>
<Separator Background="DarkGray"/>
<ListBox Background="{DynamicResource BG}" BorderThickness="0" VerticalAlignment="Stretch" >
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
</ListBox>
</Grid>
</StackPanel>
</Border>
I tried adding a Scroll viewer instead but that didn't work properly. 我尝试添加滚动查看器,但无法正常工作。 Am I doing something wrong or what might me the problem? 我是在做错事还是我可能出什么问题?
Just remove the StackPanel
in your xaml code. 只需在您的xaml代码中删除StackPanel
。 You don't need it and makes only problems. 您不需要它,只会遇到问题。 I would suggest changing your styling layout because you don't use a Grid
like you should. 我建议您更改样式布局,因为您不应该使用Grid
。
At least add some RowDefinitions
to layout your UI when you want to show the Label
at top and the List
under the Label
. 当您想在顶部显示Label
并在Label
下显示List
时,至少添加一些RowDefinitions
来布局UI。
Could look like this 看起来像这样
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0"
Height="30"
Content="Geöffnete Designs"
HorizontalContentAlignment="Center" />
<Separator Grid.Row="1"
Background="DarkGray" />
<ListBox Grid.Row="2"
BorderThickness="0"
VerticalAlignment="Stretch">
Just add a scroll viewer in your xaml 只需在您的XAML中添加滚动查看器
<ScrollViewer>
<Border BorderThickness="1">
<StackPanel>
<Grid>
<Label Height="30" Content="Geöffnete Designs" HorizontalContentAlignment="Center"></Label>
<Separator Background="DarkGray"/>
<ListBox BorderThickness="0" VerticalAlignment="Stretch" >
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
<ListBoxItem>
<Label Content="Hallo"></Label>
</ListBoxItem>
</ListBox>
</Grid>
</StackPanel>
</Border>
</ScrollViewer>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.