图像未拉伸到整个客户区域

时间:2013-08-14 07:17:07

标签: wpf xaml

Visual Studio 2012,WPF C#Windows应用程序。 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>

图像没有拉伸到整个窗口,正如我想要的那样,它仅在1/4窗口区域显示。我希望Stretch="Fill"必须将图像拉伸到整个窗口。有什么问题?

enter image description here

1 个答案:

答案 0 :(得分:1)

问题在于您的外部GridGrid将重新调整大小以适合其子项的大小,但在这种情况下,孩子(Image)正在尝试拉伸以填充其父级的大小,因此我将猜测你所看到的是正在绘制实际尺寸的图像。

尝试使用DockPanel代替填充所有可用的父级空间子级。

<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>