ListView中的项目未正确拉伸

时间:2014-09-11 09:23:39

标签: c# wpf xaml windows-store-apps

我使用ListView作为GridView的ItemTemplate。问题是我无法获取listview中的文本框来填充可用的垂直空间,而是只使用所需的空间: enter image description here

为什么忽略我设置的VerticalAlignment="Stretch"

<ListView Margin="0,0,0,0" 
    Width="200" 
    SelectionMode="None">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>
        <ComboBox>
            <ComboBoxItem Tag="1" Content="1"/>
        </ComboBox>
        <TextBox AcceptsReturn="True" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="Should fill everything" />
    </ListView>

1 个答案:

答案 0 :(得分:1)

您必须以这种方式将ListView放在GridLayout中:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <ComboBox Grid.Row="0" .... />
    <ListView Grid.Row="1" .... />
</Grid>