2011-09-22 74 views
3

我剛剛開始學習C#WPF與一個基本的空項目,我想做一個網格,背景圖像,完全伸過窗口。拉伸網格到窗口大小

它現在的樣子,網格延伸,但不是我想要的方式。例如我的背景圖片是1000x1000px,窗口大小是1700x1200px,所以網格拉伸到1200x1200px(它保持了圖像的高寬比。我不想這樣,我只是想把它拉伸到窗口的全部)。

這裏是我的代碼:。

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

任何幫助將是巨大的,感謝

回答

10

嘗試

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

這工作太:) –

1

想通弄明白了,這是把事情搞亂了我的<Grid.ColumnDefinitions>刪除了,它的工作:)

+1

是,列被拉伸不應該有'WIDTH = 「自動」'。 –