【发布时间】:2013-05-17 19:09:13
【问题描述】:
我在 Windows Phone 8 应用程序上的 ListBoxItem 存在问题,同时试图让它们延伸到 ListBox 的所有宽度。
我的ListBox:
<ListBox
ItemsSource="{Binding Events}"
behaviors:ItemClickCommandBehavior.Command="{Binding EventSelectedCommand}"
ItemTemplate="{StaticResource EventListTemplateSelector}"/>
并且它的 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>
我无法让这些项目真正拉伸,我不知道问题出在哪里。我试图设置ItemContainerStyle HorizontalCONntentAlignment="Stretch" 但它没有用。我已经尝试了许多其他组合,似乎只有将边框或网格宽度设置为常量才有效,而另一种可行的解决方案是将边框宽度设置为绑定到包含列表框的实际宽度,但我想使用拉伸变种,如果可以使它工作。
【问题讨论】:
标签: wpf xaml windows-phone-8 listbox listboxitem