我已经在Scrollviewer中使用了Listview,并且Listview的ItemsPanelTemplate为WrapPanel作为水平方向,而DataTemplate则具有元素。
在我的列表视图中,我不希望为此启用scrollviewer可视性。如果我禁用了Scrollviewer的“水平”和“垂直”可见性,则Listview项不会滚动到特定的索引,而其下一个和上一个按钮单击。
XAML文件:
<ScrollViewer
Grid.Row="1"
Grid.Column="1"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Disabled"
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel">
<ListView
x:Name="ImageSlider"
ItemsSource="{Binding ImagesList}"
Template="{StaticResource NoScroll}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.ScrollUnit="Pixel">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<cachedImage:Image
x:Name="ImageField"
Source="{Binding Images}"
Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}},Path=ActualWidth}"
Height="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Grid}},Path=ActualHeight}"
Stretch="Fill"
Style="{StaticResource imageStyle}"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
<Setter Property="HorizontalAlignment"
Value="Stretch" />
<Setter Property="VerticalAlignment"
Value="Stretch"/>
<Setter Property="VerticalContentAlignment"
Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type
ListViewItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</ScrollViewer>
<Button
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
BorderThickness="0"
Height="30"
Width="30"
Click="ButtonDown_Click">
<Image
Source="/CCRIS;component/Resources/Images/LeftArrow.png"
RenderTransformOrigin="0.75,0.875"/>
</Button>
<Button
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Height="30"
Width="30"
Click="ButtonUp_Click">
<Image
Source="/CCRIS;component/Resources/Images/RightArrow.png"/>
</Button>
如果我单击“下一步”按钮,scrollviewer应该从列表视图的第一项滚动到listview的下一项;如果我单击上一个按钮,scrollviewer应该从当前的项目滚动到上一项目。