2010-02-26 67 views
1

我是Silverlight的新品牌,我在空間上遇到了困難。正如你在下面看到的,我在Horizo​​ntal StackPanel中有兩行標籤。當它們顯示時,它們之間有很大的空間(大約一英寸)。我無法弄清楚如何減少這個間距。高度特徵似乎並沒有這樣做。Silverlight中的間距

在此先感謝。

<UserControl x:Class="SilverlightApplication1.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" Margin="10"> 
    <StackPanel x:Name="LayoutRoot" Background="LightGray" Margin="10"> 
     <StackPanel Orientation="Horizontal" Height="50" Width="500" Margin="10"> 
      <TextBlock Height="15" Width="100" Margin="20"/> 
      <TextBlock Text="Heading" Height="15" Width="100" Margin="10"/> 
      <TextBlock Text="PDOF" Height="15" Width="100" Margin="15"/> 
      <TextBlock Text="PDOF" Height="15" Width="100" Margin="15"/> 

     </StackPanel> 
     <StackPanel Orientation="Horizontal" Height="50" Width="500" Margin="10"> 
      <TextBlock Height="15" Width="100" Margin="20"/> 
      <TextBlock Text="(degrees)" Height="15" Width="60" Margin="10"/> 
      <TextBlock Text="locked" Height="15" Width="40" Margin="10"/> 
      <TextBlock Text="(degrees)" Height="15" Width="100" Margin="15"/> 
      <TextBlock Text="(O'Clock)" Height="15" Width="100" Margin="15"/> 

     </StackPanel> 
    </StackPanel> 
</UserControl> 

回答

2

通過指定餘量爲單一值Margin="10"要指定圍繞每個邊沿的10相等的餘量,左,上,右,下。

你需要分割的利潤率爲剛剛得到它的左和右說:

Margin="10,0,20,0" 

通過這樣做只能有一個在左,右,而不是頂部和底部的餘量。這將需要適用於所有元素,因爲利潤率是累積的。

有一個在MSDN pageMargin更多信息:

<frameworkElement Margin="uniform"/> 
- or - 
<frameworkElement Margin="left+right,top+bottom"/> 
- or - 
<frameworkElement Margin="left,top,right,bottom"/> 

所以單個值是一個統一的間距,一對價值的分割水平和垂直邊緣,並且具有所有四個值讓你完全控制所有四。

你的情況,你可以簡單地有:

Margin="10,0" 

沒有垂直邊距指定水平邊距,或

Margin="15,10" 

指定水平邊距,但較小的垂直邊距。

這從頁面圖像演示如何這最後一個將應用於:

alt text http://i.msdn.microsoft.com/ms600890.margin_and_alignment_3%28en-us,VS.95%29.png

0

感謝ChrisF他的迴應。我決定採用不同的方式。我使用Canvas而不是StackPanel。