我在使用ListView时遇到问题,我需要以全屏显示此列表。我的ItemSource中有55行。
这是我的代码段。
<Grid Grid.Row="0" BackgroundColor="#5FB1E0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackLayout Grid.Column="0" Margin="10">
<Image x:Name="ImageMenu" Source="{local:ImageResource HRiS.images.menu.png}" HeightRequest="40"></Image>
</StackLayout>
<Label Grid.Column="1" x:Name="LabelHome" FontSize="18" TextColor="White" VerticalTextAlignment="Center"></Label>
</Grid>
<ListView Grid.Row="1" x:Name="listEmployeeDirectory" HasUnevenRows="True" VerticalOptions="FillAndExpand"
IsPullToRefreshEnabled="True" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="5,10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" HeightRequest="50">
<Image.Source>
<UriImageSource Uri="{Binding ProfileImage}" CacheValidity="5" CachingEnabled="true" />
</Image.Source>
</Image>
<Label Grid.Column="1" Text="{Binding FullName}" HorizontalOptions="StartAndExpand"
VerticalTextAlignment="Center" TextColor="Black" FontSize="18" FontFamily="Droid Sans Mono" />
</Grid>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
这是屏幕截图。
最佳答案
试试这个,您只需要放置您的元素
<Grid VerticalOptions="StartAndExpand" HorizontalOptions="CenterAndExpand" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Margin="10" HeightRequest="50" BackgroundColor="Gray" Orientation ="Horizontal">
<Image HeightRequest="10"/>
<Label Text="Test" FontSize="18" TextColor="White" VerticalTextAlignment="Center"/>
</StackLayout>
<ListView Grid.Row="1" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" IsVisible="true" ItemTapped="ItemTapped" ItemsSource="{Binding Projects}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee" Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding image}"/>
<Label Text="{Binding title}" TextColor="#f35e20" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackLayout Grid.Row="2" Margin="10" HeightRequest="50" BackgroundColor="Gray" Orientation ="Horizontal">
<Label Text="Test" FontSize="18" TextColor="White" VerticalTextAlignment="Center"></Label>
</StackLayout>
</Grid>