2013-02-16 40 views
0

我剛開始使用WPF,我試圖設置一個四行高150的網格。這將佔用我爲高度設置的800個像素中的600個像素。然後,我將頂部保證金設置爲30,我的底部保證金設置爲170,爲底部的控制提供了一些空間。WPF頁邊距不加起來

在設計視圖中一切看起來都很棒,但是當我運行我的應用程序時,最下面一行有一些區域被切斷。

設計視圖 enter image description here

運行View enter image description here

我不明白是什麼原因造成這些觀點之間的這種差異。

<Page x:Class="EzTargetProject.HomePage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="800" d:DesignWidth="1280" 
Title="HomePage"> 

<Grid Margin="20,30,20, 170" Grid.Column="4" Grid.Row="4" Background="Gray" ShowGridLines="True"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="150"/> 
     <RowDefinition Height="150"/> 
     <RowDefinition Height="150"/> 
     <RowDefinition Height="150"/> 
    </Grid.RowDefinitions> 

    <!-- Name --> 
    <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" /> 
</Grid> 

+0

我可能已經注意到問題是什麼,但如果有人能給我一個,我想確認一下。頁面的導航欄是否考慮了頁邊空白,這意味着導航欄的邊距是多少? – 2013-02-16 17:55:38

回答

1

可以避開底部邊緣,如果你想設置網格的高度。

如果你總是想要一個600px高度的網格,只需設置它。

我會使用一個ScrollViewer中作爲父母,讓用戶看到你會在網格下設置(如果用戶希望有forexample一個小窗口)控件: Enabling Scrollbar in WPF

+0

完美的工作,使我的設計更靈活的其他屏幕。我會在5分鐘內給你答案。謝謝。 – 2013-02-16 18:03:04

+0

順便說一句,因爲導航欄上面的方式不工作? – 2013-02-16 18:03:45

+0

我想這是因爲它總是試圖讓邊緣...並沒有在網格下170px。我不知道這個窗口是否比設計窗口更小,或者窗口的底部是否被分配給了另一個元素8-) – zapico 2013-02-16 18:07:38