当ItemsPanel是水平StackPanel时,WinRT拉伸ListBox内容

时间:2014-10-09 11:19:30

标签: xaml listbox windows-store-apps

在此输入图片说明我有ListBoox

<ListBox>
    <x:String>1</x:String>
    <x:String>2</x:String>
    <x:String>3</x:String>
    <x:String>4</x:String>

    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
     </ListBox.ItemContainerStyle>
     <ListBox.ItemTemplate>
         <DataTemplate>
             <Grid Background="Green" >
                 <TextBlock Text="{Binding}" />
             </Grid>
         </DataTemplate>
      </ListBox.ItemTemplate>
      <ListBox.ItemsPanel>
          <ItemsPanelTemplate> 
              <StackPanel Orientation="Horizontal" Background="Yellow"></StackPanel>
          </ItemsPanelTemplate>
       </ListBox.ItemsPanel>
</ListBox>

我需要在整个屏幕(列表)中拉伸ListBox的项目。如果StackPanel的方向是垂直的,它可以很好地工作,但在我的情况下,方向是水平的,它根本不起作用。任何想法,建议 - 我需要帮助

1 个答案:

答案 0 :(得分:0)

您可以使用

HorizontalAlignment="Stretch"

在整个空间内拉伸像StackPanel这样的XAML容器。