2016-12-30 78 views
1

我有ListView的問題,我需要出示該列表以全屏顯示。在我的ItemSource中有55行。的ListView [Xamarin.Forms]

這是我的代碼片段。

<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> 

以下是截圖。 enter image description here

+0

什麼是您的第1行的行定義是什麼?我的意思是我很抱歉,行 – Mounika

+0

的高度,RowDefinition的行0是汽車,第1行是*(星號) –

回答

0

這個問題解決了,我用了網格佈局,現在我已經把它改成StackLayout和它的正常工作現在。

謝謝:)

<StackLayout AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" x:Name="HomeChildContainer"> 
      <Grid BackgroundColor="#297FB8"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="50"> 
        </ColumnDefinition> 
        <ColumnDefinition Width="*"> 
        </ColumnDefinition> 
        <ColumnDefinition Width="Auto"> 
        </ColumnDefinition> 
       </Grid.ColumnDefinitions> 
       <StackLayout Grid.Column="0" Margin="10" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"> 
        <Image x:Name="ImageMenu" Source="menu.png" HeightRequest="40" /> 
       </StackLayout> 
       <Label Grid.Column="1" x:Name="LabelHome" FontSize="18" TextColor="White" VerticalTextAlignment="Center"> 
       </Label> 
      </Grid> 
      <Entry Grid.Row="1" x:Name="TextSerach" Keyboard="Chat" Placeholder="Search Employee" FontSize="13" FontFamily="Droid Sans Mono" /> 
      <ListView Grid.Row="2" x:Name="listEmployeeDirectory" HasUnevenRows="True" VerticalOptions="FillAndExpand" IsPullToRefreshEnabled="True" HorizontalOptions="FillAndExpand"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <ViewCell> 
          <StackLayout Padding="5,10"> 
           <Grid> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Width="Auto"> 
             </ColumnDefinition> 
             <ColumnDefinition Width="*"> 
             </ColumnDefinition> 
            </Grid.ColumnDefinitions> 
            <Image Grid.Column="0" Source="{Binding ProfileImage}" HeightRequest="50"> 
            </Image> 
            <Label Grid.Column="1" Text="{Binding FullName}" HorizontalOptions="StartAndExpand" VerticalTextAlignment="Center" TextColor="Black" FontSize="16" FontFamily="Droid Sans Mono" /> 
           </Grid> 
          </StackLayout> 
         </ViewCell> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 
     </StackLayout> 
1

試試這個你只需把你的元素

<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> 

enter image description here

+1

謝謝,我現在想這個。 –

+0

我仍然無法以全屏顯示列表視圖,我在ContentView中使用listview –

+0

在您的ContentPage中使用相同的代碼。 – sumeet

相關問題