2010-02-26 72 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。