In stackpanel, I want two textblocks in same row.
in the image, I want the date and time at the same row. what should I do?
Following is source code:
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Title}" Margin="15,0,15,0"/>
<TextBlock Text="2015/03/01" Margin="15,0,15,10" HorizontalAlignment="Left"/>
<TextBlock Text="1:42:31" Margin="15,0,15,10" HorizontalAlignment="Right"/>
</StackPanel>
答案 0 :(得分:6)
StackPanel的默认方向是垂直,因此三个TextBlock一个在另一个下面。您应该添加另一个StackPanel,其Orientation设置为Horizontal,并将底部的两个TextBlocks放在其中。
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="Title" Margin="15,0,15,0"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="2015/03/01" Margin="15,0,15,10" HorizontalAlignment="Left"/>
<TextBlock Text="1:42:31" Margin="15,0,15,10" HorizontalAlignment="Right"/>
</StackPanel>
</StackPanel>
更新:
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="Title" Margin="15,0,15,0"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="2015/03/01" Grid.Column="0" Margin="15,0,15,10" HorizontalAlignment="Left"/>
<TextBlock Text="1:42:31" Grid.Column="1" Margin="15,0,0,10" HorizontalAlignment="Right"/>
</Grid>
</StackPanel>