2016-03-03 60 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

嗨安德里谢谢你的回答,但这并没有改变任何东西。 –