简体   繁体   中英

Why images are not stretched in vertical size in this xaml code?

I have this xaml code:

 <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="640*" />
                <ColumnDefinition Width="14"/>
                <ColumnDefinition Width="350*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="40"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

<ListView Grid.Column="0" Grid.Row="2"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"                     ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionMode="Single" >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Border x:Name="border" BorderBrush="Black" BorderThickness="1" Margin="0,1,0,0">
                            <Grid  Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Stretch">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" MinWidth="300"/>
                                    <ColumnDefinition Width="4"/>
                                    <ColumnDefinition Width="*" MinWidth="300"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" MinHeight="150"/>
                                    <RowDefinition Height="4"/>
                                    <RowDefinition Height="20" />
                                </Grid.RowDefinitions>
                                <Image Grid.Column="0" Grid.Row="0"  Stretch="UniformToFill" StretchDirection="Both">
                                    <Image.Source>                                        
                                    </Image.Source>
                                </Image>
                                <TextBlock Grid.Column="0" Grid.Row="2"   FontWeight="Black" TextAlignment="Center" >
                                    <TextBlock.Text >
                                    </TextBlock.Text>
                                </TextBlock>
                                <Image Grid.Column="2" Grid.Row="0"   Stretch="UniformToFill" StretchDirection="Both" >
                                    <Image.Source>
                                    </Image.Source>
                                </Image>
                                <TextBlock Grid.Column="2" Grid.Row="2" FontWeight="Black" TextAlignment="Center" >
                                    <TextBlock.Text >
                                    </TextBlock.Text>
                                </TextBlock>

                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
 </Grid>

when I resize the window that this xaml is on it, I can see that image are resize to fill the width, but they are not resized to fill the height. If the image is too big for the height, the top of image is shown and not the bottom section.

How can I change this xaml that when width or height is changes, the image size in the list view also changes?

See the documentation
UniformToFill preserves aspect
I think you want Fill

Stretch Enumeration

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