StackPanel到网格

时间:2011-07-24 20:53:30

标签: silverlight xaml grid windows-phone

如何将stackpanel转换为网格?

            <DataTemplate >
              <Grid Margin="0,5">
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto"/>
                  <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image delay:LowProfileImageLoader.UriSource="{Binding image_uri}" Width="50" Height="50" VerticalAlignment="Top" Stretch="None" />
                <StackPanel  Grid.Column="1" >
                  <Line  Stroke="#4284B0" StrokeDashArray="4 2" X2="380"/>
                  <TextBlock  Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Margin="{StaticResource PhoneHorizontalMargin}" MinHeight="20" Text="{Binding author_name}">
                <TextBlock.Foreground>
                    <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
                </TextBlock.Foreground>
                  </TextBlock>
                  <TextBlock Text="{Binding text}"  Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Margin="{StaticResource PhoneHorizontalMargin}" MinHeight="40" MaxHeight="180"/>
                  <TextBlock Text="{Binding Date_Time}" Style="{StaticResource PhoneTextSmallStyle}" Margin="{StaticResource PhoneHorizontalMargin}" Height="20" HorizontalAlignment="Left" Width="133"/>
                  <TextBlock Text="{Binding likes_count}" Style="{StaticResource PhoneTextSmallStyle}" Margin="181,-20,0,0" Height="20" Width="77" HorizontalAlignment="Left"/>
                  <TextBlock Text="{Binding comm_count}" Style="{StaticResource PhoneTextSmallStyle}" Margin="289,-20,0,0" Height="20" Width="77" HorizontalAlignment="Left"/>
                  <Image Height="21" Margin="154,-19,0,0" Source="/Images/like.png" HorizontalAlignment="Left" Width="20"/>
                  <Image Source="/Images/ico_comments.png" Stretch="Fill" HorizontalAlignment="Left" Width="21" Margin="264,-19,0,0" />
                </StackPanel>
              </Grid>
            </DataTemplate>

我不知道该怎么做。我试过:

<Grid  Grid.RowSpan="5" Margin="5,0,0,0" VerticalAlignment="Top" Width="380" >
                          <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                          </Grid.RowDefinitions>
                          <Line Grid.RowSpan="0" 

但我的内容看起来像拼凑在一起。请帮助我。 我想转换,因为我需要提高性能。

3 个答案:

答案 0 :(得分:2)

考虑到你正在使用TextWrapping,并且由此似乎需要动态高度,使用Grid与使用stackpanel没有太大区别。

如果您无法弄清楚如何使用网格,我会建议您read a tutorial,也许install Expression Blend

这不是发布一些代码的正确位置,并希望人们为您转换它。

答案 1 :(得分:2)

我假设您希望StackPanel中的所有内容现在都在Grid

<Grid Grid.Column="1">
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <!--Add as many row definitions as you need-->
  </Grid.RowDefinitions>

  <Line Grid.Row="0" />
  <TextBlock Grid.Row="1" />

  <!-- The rest of your TextBlocks, Images etc. add a row number for each-->

</Grid>

答案 2 :(得分:1)

  <Grid x:Name="LayoutRoot" Background="Aqua" Margin="20" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Ellipse Fill="Red" Stroke="Black" MinWidth="75" MinHeight="75" Grid.Row="0" Stretch="Uniform"/>
        <Ellipse Fill="#FF57F61F" Stroke="Black" MinWidth="75" MinHeight="75"  Grid.Row="1"/>
        <Ellipse Fill="#FF3D13F0" Stroke="Black" Width="75" Height="75"  Grid.Row="2"/>

    </Grid>