简体   繁体   中英

How do I stretch my grid inside a ListView

I'm trying to stretch the orange grid so that it fills out horizontally, currently it only fills out the length of the textblock that's inside. Why is that?

<ListView ItemsSource="{Binding Users}"
          Grid.Column="0">

    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid Height="50"
                  Background="Orange"
                  HorizontalAlignment="Stretch">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Rectangle RadiusX="20" RadiusY="20"
                           Width="30" Height="30">
                    <Rectangle.Fill>
                        <SolidColorBrush Color="Orange" />
                    </Rectangle.Fill>
                </Rectangle>

                <StackPanel Grid.Column="1"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Stretch">
                    <TextBlock Text="{Binding }"
                               FontWeight="Bold"
                               HorizontalAlignment="Stretch"/>
                </StackPanel>

                <Grid.Effect>
                    <DropShadowEffect Opacity=".1"
                                      BlurRadius="10"
                                      Direction="280"/>
                </Grid.Effect>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

This is what it looks like在此处输入图片说明

I forgot to add HorizontalContentAlignment="Stretch" to the ListView.

<ListView ItemsSource="{Binding Users}"
          Grid.Column="1"
          HorizontalContentAlignment="Stretch">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM