我正在處理Windows Phone 7的照片庫,我試圖讓每個圖像都採用全屏並水平滑動。 我到目前爲止做的是使用我已修改爲水平滾動的列表框,但問題是,我似乎無法找到一種方法來綁定ListboxItem的寬度和高度與ActualWidth和ActualHeight列表框本身。 我想這樣做的原因是,如果手機的方向改變,照片的大小也會改變以適應屏幕。Silverlight - 綁定列表框ActualWidth到ListboxItem寬度
以下是到目前爲止我有(我已經使用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>
任何想法如何實現這個結果?
感謝
您可以選擇添加以下代碼到你的應用程序頁面的構造函數? SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape; – 2010-09-05 22:01:52