【问题标题】:Spacing in SilverlightSilverlight 中的间距
【发布时间】:2010-02-26 15:38:40
【问题描述】:

我是 Silverlight 的新手,我很难处理间距。正如您在下面看到的,我在水平 StackPanel 中各有两行标签。当它们显示时,它们之间有很大的空间(大约一英寸)。我不知道如何减少这个间距。身高特征好像不行。

提前致谢。

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

【问题讨论】:

    标签: .net asp.net silverlight-3.0


    【解决方案1】:

    通过将边距指定为单个值Margin="10",您将在每条边(左、上、右、下)周围指定相等的边距 10。

    你需要把边距分开,让它在左边和右边说:

    Margin="10,0,20,0"
    

    通过这样做,只有左右边距,而不是顶部和底部。这需要应用于所有元素,因为边距是累积的。

    关于MSDN page 的更多信息Margin

    <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

    【讨论】:

      【解决方案2】:

      感谢 ChrisF 的回复。我决定采用不同的方法。我使用 Canvas 而不是 StackPanel。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-30
        • 2011-09-24
        • 1970-01-01
        • 2014-06-17
        • 1970-01-01
        相关资源
        最近更新 更多