我ListBoxItem在Windows Phone 8应用程序上遇到问题,同时试图让它们伸展到所有宽度ListBox.
我的ListBox:
<ListBox
ItemsSource="{Binding Events}"
behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}"
ItemTemplate="{StaticResource EventListTemplateSelector}"/>
Run Code Online (Sandbox Code Playgroud)
它的DataTemplates在一个单独的xaml资源文件中:
<DataTemplate x:Key="EventListHeaderTemplate">
<Border HorizontalAlignment="Stretch">
<Grid Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding ImageUri}" VerticalAlignment="Center" HorizontalAlignment="Center" Height="30"/>
<TextBlock Grid.Column="1" Text="{Binding SomeText}" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="Black"/>
</Grid>
</Border>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我不能让这些物品真正拉伸,我不知道问题出在哪里.我试图设置ItemContainerStyleHorizontalCOntentAlignment ="Stretch",但它不起作用.我已经尝试了许多其他组合,似乎只将Border或Grid宽度设置为常量工作,另一个有效的解决方案是将Border宽度设置为绑定到包含ListBox的ActualWidth,但我想使用Stretch变种如果可以使它工作.