0

Visual Studio 2012, WPF C# Windows Application. XAML:

<Window x:Class="Edge.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid Background="Blue">
        <Image Source="Images/House.png"  
           HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
           Stretch="Fill" Margin="3"
           />
    </Grid>
</Window>

Image is not stretched to the whole window, as I want, it is shown only in 1/4 window area. I expect that Stretch="Fill" must stretch the image to the whole window. What is wrong?

enter image description here

4

1 回答 1

2

问题是你的外在Grid。AGrid将重新调整大小以适合其子项的大小,但在这种情况下,子项 (the Image) 正试图拉伸以填充其父项的大小,所以我猜你所看到的是正在绘制的图像实际尺寸。

尝试使用 aDockPanel来填充所有可用的父空间子空间。

<Window x:Class="Edge.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <DockPanel Background="Blue">
        <Image Source="Images/House.png"  
           HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
           Stretch="Fill" Margin="3"/>
    </DockPanel> 
</Window>
于 2013-08-14T07:22:17.903 回答