[英]Listbox items not filling the entire width of screen WP7
我正在嘗試創建一個包含以下模板的項目的列表框
<ListBox x:Name="moviesactedin" Style="{StaticResource ListBoxStyle2}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,0,0,1" BorderBrush="Black" Margin="0,0,0,5">
<StackPanel Orientation="Horizontal" Margin="0,0,0,5" HorizontalAlignment="Stretch">
<Image Source="{Binding Image}" Stretch="None" Margin="0,0,5,5" />
<StackPanel Orientation="Vertical" Margin="10,0,0,0" VerticalAlignment="Top">
<TextBlock Text="{Binding Title}" Foreground="Black" FontWeight="Bold"/>
<TextBlock Text="{Binding Director}" Foreground="Black"/>
<TextBlock Text="{Binding ReleaseDate}" Foreground="Black"/>
</StackPanel>
<Image Source="/Images/icon_arrow.png" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
和列表框樣式
<Style x:Key="ListBoxStyle2" TargetType="ListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<ItemsPresenter HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
第一個圖像位於左側,帶有三個文本塊的stackPanel位於中間,第二個圖像位於右側(末尾)。
問題是列表框項沒有填滿屏幕的整個寬度,因此我將在屏幕寬度的末尾擁有最后一張圖像。
有什么幫助嗎?
這工作
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
這些項目將填滿整個屏幕。 感謝Fabrice提供的線索。
你可以嘗試一下嗎?
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/></Style>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.