【发布时间】:2013-09-30 19:58:59
【问题描述】:
我有几个TextBlock,我希望将它们组合在一起,这样如果其中一个恰好包含大量文本,它下面的控件就会相应地向下移动。
目前我已经将TextBlock 包裹在<StackPanel> 中,但是,控件现在被广泛地垂直分离。我怎样才能缩短它们之间的距离?
这是我的代码:
<StackPanel>
<TextBlock TextAlignment="Left" x:Name="lblCategoryTitle" TextWrapping="Wrap" Text="Category"
VerticalAlignment="Top" Height="29" Width="456" Margin="0,59,0,0" FontWeight="Bold">
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource PhoneAccentColor}" />
</TextBlock.Foreground>
</TextBlock>
<TextBlock Height="auto" TextAlignment="Left" x:Name="lblCategory" TextWrapping="Wrap"
Text="Category" Margin="0,88,10,428" />
<TextBlock TextAlignment="Left" x:Name="lblContactDetails" TextWrapping="Wrap"
Text="Contact Details" Margin="0,179,289,396" FontWeight="Bold">
<TextBlock.Foreground>
<SolidColorBrush Color="{StaticResource PhoneAccentColor}" />
</TextBlock.Foreground>
</TextBlock>
<TextBlock Height="auto" TextAlignment="Left" x:Name="lblName" TextWrapping="Wrap" Text="Name"
Margin="0,211,10,364" />
<TextBlock Height="auto" TextAlignment="Left" x:Name="lblAddress" TextWrapping="Wrap"
Text="Address" Margin="0,243,10,332" />
<TextBlock Height="auto" TextAlignment="Left" x:Name="lblEmail" TextWrapping="Wrap" Text="Email"
Margin="0,275,10,300" />
<TextBlock Height="auto" TextAlignment="Left" x:Name="lblTelephone" TextWrapping="Wrap"
Text="Telephone" Margin="0,307,10,268" />
</StackPanel>
我想我还应该问一下StackPanel 是否适合我的要求。大家觉得呢?
【问题讨论】:
-
你的页边距太大了,它们把控件分开了,已经不是绝对定位了。大多数情况下只需使用
Margin="12,0,0,12"。
标签: xaml windows-phone-8 windows-phone