我有一个应该显示信息并测试它的视图我添加了testdata。但是,如果我为屏幕空间添加了太多项目,则不会出现垂直滚动条。
这是我的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>
我尝试添加一个Scroll查看器但是没有正常工作。我做错了什么或者我的问题是什么?
答案 0 :(得分:2)
只需删除xaml代码中的StackPanel
即可。你不需要它,只会产生问题。我建议你改变你的造型布局,因为你没有像你应该那样使用Grid
。
如果您希望在顶部显示RowDefinitions
而在Label
下显示List
,则至少添加一些Label
来布局您的用户界面。
看起来像这样
<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">
答案 1 :(得分:0)
只需在xaml中添加滚动查看器
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (!(getActivity() instanceof DateListener)) {
throw new ClassCastException("The activity inflating this fragment must implement DateListener!");
}
dateListener = (DateListener) getActivity();
}