启用水平滚动XAML

时间:2015-02-11 07:20:49

标签: xaml listview windows-store-apps horizontal-scrolling

我有以下XAML:

        <Grid>

            <ListView x:Name="IconTextGrid" Height="500">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Width="220" Height="60">
                            <Border Background="#66727272" Width="40" Height="40" Margin="10">
                                <Image Source="/SampleImage.png" Height="32" Width="32" Stretch="UniformToFill"/>
                            </Border>
                            <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                                <TextBlock Text="Ay Lorem Ipsum" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis" />
                                <TextBlock Text="Dolor sit amet" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis"/>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>

                </ListView.ItemTemplate>
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <ItemsWrapGrid MaximumRowsOrColumns="8"/>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ScrollViewer HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto"/>
            </ListView>

        </Grid> 
</Page>

哪个应该呈现可由用户选择的项目。 这里的问题是,当我有多个项目(超过100个)时,没有水平滚动。 我的问题是为什么以及如何解决它? 感谢。

1 个答案:

答案 0 :(得分:0)

尝试这样做......

<Grid>
  <ScrollViewer HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto"> 
     <ListView x:Name="IconTextGrid" Height="500">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Width="220" Height="60">
                        <Border Background="#66727272" Width="40" Height="40" Margin="10">
                            <Image Source="/SampleImage.png" Height="32" Width="32" Stretch="UniformToFill"/>
                        </Border>
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                            <TextBlock Text="Ay Lorem Ipsum" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis" />
                            <TextBlock Text="Dolor sit amet" Margin="10,0,0,0" Width="170" Height="20" TextTrimming="WordEllipsis"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <ItemsWrapGrid MaximumRowsOrColumns="8"/>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>                
        </ListView>
    </ScrollViewer>
</Grid>