如何使堆叠面板对齐?

时间:2013-11-25 14:01:40

标签: xaml windows-phone-7

在我的应用程序中,我使用的是一个列表,其中包含四个数据1)名称2)日期3)图像4)petname 结束我用过的xaml代码,

<StackPanel Orientation="Horizontal" Width="450" Height="90" HorizontalAlignment="Stretch">
            <StackPanel Margin="0,0,0,0" Orientation="Horizontal">
                <Grid Margin="0,0,0,0" Height="90" Width="225">
                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Height="60" Margin="0,15" FontWeight="Medium" TextWrapping="Wrap" Text="{Binding Name}" Width="225" FontSize="25"/>
                    <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Height="39" Margin="4,51,0,0" TextWrapping="Wrap" Text="{Binding Date}" Width="221" Foreground="Gray" FontSize="16"/>
                </Grid>
                <StackPanel Orientation="Horizontal" Grid.Row="0" Width="225" HorizontalAlignment="Right">
                    <Image Name="ImgBox" Height="46" Source="/attach-30x30.png" VerticalAlignment="Center" Width="40" HorizontalAlignment="Right"/>
                    <TextBlock Text="{Binding petname}" FontSize="24" HorizontalAlignment="Right" VerticalAlignment="Center" FontFamily="Portable User Interface"/>
                </StackPanel>
            </StackPanel>
        </StackPanel>

我想要的是,我希望图片后面跟着petname,两者都应该是正确的。 我想要的是, this one

但我得到的是, this one

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

为内部堆栈面板设置FlowDirection = RighToLeft,然后交换图像和文本块的顺序

答案 1 :(得分:0)

您的网格应跨越所有控件。试试这个样本:

<StackPanel Orientation="Horizontal" Width="450" Height="90" HorizontalAlignment="Stretch">
                <Grid Margin="0,0,0,0" Height="90" Width="450">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock HorizontalAlignment="Left" Grid.Column="0" VerticalAlignment="Center" Height="60" Margin="0,15" FontWeight="Medium" TextWrapping="Wrap" Text="{Binding Name}" Width="225" FontSize="25"/>
                    <TextBlock HorizontalAlignment="Left" Grid.Column="0" VerticalAlignment="Center" Height="39" Margin="4,51,0,0" TextWrapping="Wrap" Text="{Binding Date}" Width="221" Foreground="Gray" FontSize="16"/>

                    <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                        <Image Name="ImgBox" Height="46"  Source="/attach-30x30.png" VerticalAlignment="Center" Width="40"/>
                        <TextBlock Text="{Binding petname}" FontSize="24" TextAlignment="Right" VerticalAlignment="Center" FontFamily="Portable User Interface"/>
                    </StackPanel>
                </Grid>
            </StackPanel>