2016-11-18 87 views
0

我有一個StackLayout當選擇了用戶具有動態地添加到它的項目。我希望它的高度大約爲200,那麼如果列表比這長,它應該是可滾動的。如何調整Xaml StackLayout的滾動高度?

如果我添加的高度要求,因爲它是現在,它調整高度和滾動的作品,但盒子的底部後,添加項目(防止這樣滾動條基本上是沒有意義的。

這是代碼中,StackLayout被稱爲「讀出」:。

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="Clocker.MainPage" > 
    <StackLayout x:Name="mainstack"> 
    <Picker x:Name="locationpicker" SelectedIndexChanged="locationpicker_SelectedIndexChanged" BackgroundColor="#baf4d5"></Picker> 
    <Label x:Name="timeLabel" FontSize="50" HorizontalTextAlignment="Center" VerticalTextAlignment="Start" TextColor="White" BackgroundColor="#59a092"/> 
    <ScrollView Orientation="Vertical" BackgroundColor="#baf4d5"> 
     <StackLayout x:Name="readOut"> 

     </StackLayout> 
    </ScrollView> 
    <ListView x:Name="userslist" BackgroundColor="#59a092"> 
     <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell> 
      <ViewCell.ContextActions> 
       <MenuItem Clicked="OnIn" CommandParameter="{Binding .}" 
       Text="In" /> 
       <MenuItem Clicked="OnOut" CommandParameter="{Binding .}" 
       Text="Out" IsDestructive="True" /> 
      </ViewCell.ContextActions> 
      <StackLayout Padding="15,0"> 
       <Label x:Name="lblname" Text="{Binding FullName}" TextColor="White" /> 
      </StackLayout> 
      </ViewCell> 
     </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
    </StackLayout> 
</ContentPage> 

回答

0

我在我的應用程序2次或3的頁面都或多或少像你所描述的 我的解決方案使用和2所列出 更多或更少像這樣:

 <Grid ColumnSpacing="0" RowSpacing="0"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
       <RowDefinition Height="2*" /> 
       <RowDefinition Height="8*" /> 
       <RowDefinition Height="Auto" /> 
      </Grid.RowDefinitions> 

第1行是在那裏我有我的第一個列表中,第2行是第二不勝枚舉。

我做這種方式(0是一個報頭和圖3是一個頁腳),所以我有更多或更少的在頂部的左側空間和分配給所述第二列表中的空間的其餘部分的20%。

希望很明顯。

+0

相信一定比例的屏幕上的項目,但我不認爲它會想盡一切辦法解決stacklayout的問題不滾動。 – connersz