Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 图像不会拉伸到整个客户端区域_Wpf_Xaml - Fatal编程技术网

Wpf 图像不会拉伸到整个客户端区域

Wpf 图像不会拉伸到整个客户端区域,wpf,xaml,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

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”
必须将图像拉伸到整个窗口。怎么了


问题在于您的外部
网格。
网格
将重新调整大小以适应其子对象的大小,但在本例中,子对象(图像
)试图拉伸以填充其父对象的大小,因此我猜您看到的是绘制的图像的实际大小

尝试使用
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>


网格占据了整个客户区域-请参见图片中的蓝色边框。我需要使用网格,因为在真实的程序中,我将图像放置到一个网格单元中,结果是相同的。如果不给网格一个宽度或高度,网格将调整大小以适合其子网格。你没有给你的图像一个明确的宽度或高度,那么你希望发生什么呢?谢谢,问题是图像本身-我需要从图像上剪下白色区域。真蠢…@AlexFarber不用担心伙计,我以前也做过类似的事=)@Clemens我同意。问题中的代码按预期工作。不仅网格的行为符合预期,属性的意图也是正确的。此答案不应标记为答案@Clemens-这是我的XAML页面的精确副本,应用程序除了此代码外不包含任何内容。已解决-图像显示正确,它包含白色区域,我需要将其切断。我相信您的图像中有白色。我已经在我的机器上测试了你的代码,它运行得很好。我的机器中的图像被强调了。