Two Textblocks in same row

时间:2015-05-24 20:59:13

标签: winrt-xaml

In stackpanel, I want two textblocks in same row. image

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>

1 个答案:

答案 0 :(得分:6)

StackPanel的默认方向是垂直,因此三个TextBlock一个在另一个下面。您应该添加另一个StackPanel,其Orientation设置为Horizo​​ntal,并将底部的两个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>