Stretch Grid to window size(将网格拉伸到窗口大小)
问题描述
我刚刚开始使用一个基本的空项目学习 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.
现在的方式,网格延伸,但不是我想要的方式.例如,我的背景图像是 1000x1000 像素,我的窗口大小是 1700x1200 像素,因此网格拉伸到 1200x1200 像素(它保持图像的纵横比.我不想要这个,我希望它只是在整个窗口中拉伸.
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="V2luZG93MQ==" Height="auto" Width="auto">
<Grid VerticalAlignment="Stretch">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="auto" MinWidth="510" />
    </Grid.ColumnDefinitions>
    <Image Source="C:UsersEdyPicturescool-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}}}">
                        这篇关于将网格拉伸到窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将网格拉伸到窗口大小
				
        
 
            
        - 如何用自己压缩一个 IEnumerable 2022-01-01
 - 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
 - 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
 - C# 中多线程网络服务器的模式 2022-01-01
 - 输入按键事件处理程序 2022-01-01
 - WebMatrix WebSecurity PasswordSalt 2022-01-01
 - Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
 - MoreLinq maxBy vs LINQ max + where 2022-01-01
 - C#MongoDB使用Builders查找派生对象 2022-09-04
 - 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
 
						
						
						
						
						
				
				
				
				