我无法使水平滚动ListView工作。我非常接近,但后来有些事情做得不对。
这是我目前在搜索互联网后提出的XAML。这些项目是水平显示的,但问题是它仍然只是想垂直滚动,即使我试图强制水平开启和垂直关闭所有内容。
有没有人对我做错了什么有任何见解?
<ScrollViewer x:Name="scrollWatchlist" Grid.Row="1" Margin="0,5,0,3" DataContext="{Binding MovieViewModel}"
HorizontalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible"
IsHorizontalRailEnabled="True"
VerticalScrollMode="Disabled"
VerticalScrollBarVisibility="Disabled"
IsVerticalRailEnabled="False"
IsScrollInertiaEnabled="True">
<ScrollViewer.Template>
<ControlTemplate>
<ListView Margin="0,5,0,3" ItemsSource="{TemplateBinding DataContext}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<ListViewItem Margin="0,0,5,0" Tag="{Binding ID}">
<Image Source="{Binding FormattedPosterUri}" Width="92" />
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ControlTemplate>
</ScrollViewer.Template>
</ScrollViewer>
更新:以下是遇到此问题的任何人的XAML示例:
<ListView x:Name="lvwMovieWatchlist" Grid.Row="1" Margin="0,5,0,3" ItemsSource="{Binding MovieViewModel}"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.IsHorizontalRailEnabled="True"
ScrollViewer.VerticalScrollMode="Disabled">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<ListViewItem Margin="0,0,5,0" Tag="{Binding ID}">
<Image Source="{Binding FormattedPosterUri}" Width="92" />
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:5)
您不需要ScrollViewer
,而且您应该在ListView
<ListView Margin="0,5,0,3" ItemsSource="{TemplateBinding DataContext}"ScrollViewer.HorizontalScrollMode="Enabled" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.IsHorizontalRailEnabled="True">
答案 1 :(得分:4)
建议使用GridView显示水平滚动项目。只需在代码中用Gridview替换ListView即可。
但是,您可以将ListView与水平滚动条一起使用:
<ListView ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.VerticalScrollMode="Disabled">