拉伸网格窗口大小 [英] Stretch Grid to window size

查看:183
本文介绍了拉伸网格窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习C#WPF一个基本空的项目,我想打一个网格,背景图像,绵延正好在窗户上。

I've just started learning C# WPF with a basic empty project and I want to make a grid, with a background image, which stretches exactly over the window.

现在是,电网延伸的方式,但不是我想要的方式。比如我的背景图片是1000x1000px和我的窗口大小1700x1200px所以电网延伸到1200x1200px(它保持图像的长宽比。我不想这样,我想这只是遍布窗口伸展。

The way it is now, the grid stretches, but not the way I want it. For example my background image is 1000x1000px and my window size is 1700x1200px so the grid stretches to 1200x1200px (it keeps the aspect ratio of the image. I don't want this, I want it simply to stretch all over the window.

下面是我的代码:

<Window x:Class="Backgammon.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="auto" Width="auto">
<Grid VerticalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" MinWidth="510" />
    </Grid.ColumnDefinitions>
    <Image Source="C:\Users\Edy\Pictures\cool-wallpapers1.jpg" Stretch="UniformToFill" HorizontalAlignment="Left"></Image>
    <Button Height="33" HorizontalAlignment="Right" Margin="0,0,12,12" Name="button1" VerticalAlignment="Bottom" Width="145" Click="button1_Click" ClipToBounds="False">Connect</Button>
    <ListBox Margin="12,12,0,149" Name="listBox1" HorizontalAlignment="Left" Width="225" />
</Grid>



任何帮助将是巨大的,谢谢。

Any help would be great, thanks.

推荐答案

尝试

<Grid Width="{Binding ActualWidth, RelativeSource = {RelativeSource AncestorType = {x: Type Window}}}" Height="{Binding ActualHeight, RelativeSource ={RelativeSource AncestorType = {x: Type Window}}}">

这篇关于拉伸网格窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆