我正在为 Windows Phone 7 制作照片库,我试图让每张图片都占据全屏并水平滑动。到目前为止,我正在做的是使用我已经修改为水平滚动的列表框,但问题是我似乎无法找到将 ListboxItem 的宽度和高度与列表框的 ActualWidth 和 ActualHeight 绑定的方法本身。我想这样做的原因是,如果手机的方向改变,照片的大小也会改变以适应屏幕。
以下是我到目前为止的代码(我尝试使用 TemplatedParent 和 RelativeSource 但我一定做错了,因为它根本不起作用):
<Style x:Key="PhotoGalleryItem" TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid x:Name="ListBoxItemRoot" HorizontalAlignment="Stretch" Margin="4,0,4,0" Width="{Binding RelativeSource={RelativeSource TemplatedParent},Path=ActualWidth}">
<Image Source="{Binding Mode=OneWay}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="controls:PhotoGallery">
<Setter Property="Background" Value="Red"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:PhotoGallery">
<Border BorderBrush="Transparent" BorderThickness="0" >
<Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="Scroller" VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" >
<ItemsPresenter/>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle" Value="{StaticResource PhotoGalleryItem}" />
</Style>
关于如何达到这个结果的任何想法?
谢谢