我有一个要显示的图像列表。用户应该能够放大和缩小。我可以很好地进行管理,但我希望列表也以页面为中心。每当我缩小列表时,列表就会移到左侧。
我发现this帖子看起来很有帮助,但是设置ItemContainerStyle却无济于事。我在几个控件的HorizontalAlignments上进行了一些操作(尝试拉伸和居中的多种组合。总体效果基本上是相同的(缩小时列表向左移动)。
这是我的XAML:
<Grid >
<ListView Selectionmode="None"
ScrollViewer.zoomMode="Enabled"
HorizontalContentAlignment="Center"
BorderBrush="Red"
BorderThickness="1"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto" >
<ListViewItem HorizontalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch">
<Image Source="/Assets/StoreLogo.png"
Width="500"/>
</Grid>
</ListViewItem>
<ListViewItem>
<Grid HorizontalAlignment="Stretch">
<Image Source="/Assets/StoreLogo.png"
Width="500"/>
</Grid>
</ListViewItem>
<ListViewItem>
<Grid HorizontalAlignment="Stretch">
<Image Source="/Assets/StoreLogo.png"
Width="500"/>
</Grid>
</ListViewItem>
<ListView.ItemsPanel>
<itemspaneltemplate>
<StackPanel HorizontalAlignment="Center"
BorderBrush="Blue"
BorderThickness="1"/>
</itemspaneltemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="Green" />
<Setter Property="BorderThickness" Value="1" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>