2016-03-03 59 views
2

我有這樣的ListView:UWP C#ListView控件不滾動

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <ScrollViewer VerticalScrollBarVisibility="Visible" VerticalScrollMode="Enabled"> 
     <ListView x:Name="entryList" Width="360"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <StackPanel BorderBrush="Gray"> 
         <TextBlock Text="{Binding title}"></TextBlock> 
         <TextBlock Text="{Binding description}"></TextBlock> 
         <TextBlock Text="{Binding author}"></TextBlock> 
        </StackPanel> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 
    </ScrollViewer> 
</Grid> 

我得到我的數據的ItemsSource在一個單獨的方法調用Web服務(適用所有罰款)

private async void Page_Loading(Windows.UI.Xaml.FrameworkElement sender, object args) 
{ 
    entryList.ItemsSource = await webserviceManager.getItems(param1, param2); 
} 

我的ListView充滿項目,但我不明白爲什麼它不能夠垂直滾動。檢查ScrollableHeight我總是得到0,所以我認爲這些項目是問題,控制不會將它們視爲迄今爲止的邏輯項目。如果我爲ScrollViewer提供一個具體的高度,一切都很好 - 但是這並沒有可行的解決方案,因爲我不知道應用程序稍後將在哪個設備上運行。所以我不知道我能做些什麼,也許有人可以幫助我?

編輯:數據源得到了

ObservableCollection<entryObject> objlist = new ObservableCollection<NewsObject>(); 

其中entryObject是持有類的字符串屬性的簡單數據。

回答

4

我解決了這個問題 - 通過使用RowDefinitions將所有StackPanels更改爲網格。

<ListView x:Name="entryList" Width="360"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <Grid BorderBrush="Gray"> 
        <Grid.RowDefinitions> 
         <RowDefinition></RowDefinition> 
         <RowDefinition></RowDefinition> 
         <RowDefinition></RowDefinition> 
        </Grid.RowDefinitions> 
        <TextBlock Text="{Binding title}" Grid.Row="0"></TextBlock> 
        <TextBlock Text="{Binding description}" Grid.Row="1"></TextBlock> 
        <TextBlock Text="{Binding author}" Grid.Row="2"></TextBlock> 
       </Grid> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 

此外,我用基本的SplitView更改了我的MainPage,其中內容面板中的框架使用ListView調用頁面。這裏有一個Grid.Rows現在是一個恆定的高度 - 似乎有點奇怪,但現在一切正常。

<SplitView.Content> 
    <Grid x:Name="mainPagePanel"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="50"></RowDefinition> 
      <RowDefinition></RowDefinition> 
     <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;" Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click" Grid.Row="0"/>     
     <Frame x:Name="viewFrame" Grid.Row="1"></Frame> 
    </Grid>    
</SplitView.Content> 
0

ListView已在樣式中包含ScrollViewer。所以,只要刪除你的內心ScrollViewer

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <ListView x:Name="entryList" Width="360"> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <StackPanel BorderBrush="Gray"> 
        <TextBlock Text="{Binding title}"></TextBlock> 
        <TextBlock Text="{Binding description}"></TextBlock> 
        <TextBlock Text="{Binding author}"></TextBlock> 
       </StackPanel> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
</Grid> 
+0

嗨安德里謝謝你的回答,但這並沒有改變任何東西。 –