Wpf 在windows phone开发中,如何在不定义宽度的情况下使用Textwrap属性?

Wpf 在windows phone开发中,如何在不定义宽度的情况下使用Textwrap属性?,wpf,xaml,windows-phone-7,windows-phone-8,textblock,Wpf,Xaml,Windows Phone 7,Windows Phone 8,Textblock,我使用的是单行网格。我在该行中放置了一个LongListSelector。ItemTemplate如下所示: <Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <!--when we dont mention a

我使用的是单行网格。我在该行中放置了一个LongListSelector。ItemTemplate如下所示:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition/>
    </Grid.RowDefinitions>
            <!--when we dont mention any of the height and width properties then control tries to first occupy the minimum height/width required and then it streches to the extent it is possible-->
    <phone:LongListSelector Grid.Row="0" x:Name="CLASS1">
        <phone:LongListSelector.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal"  Margin="25,20" Background="#FF616464" Width="Auto">
                    <TextBlock Text="{Binding title, Mode=TwoWay}" FontSize="40" Margin="20,20" Foreground="White" TextAlignment="Left" TextWrapping="Wrap" FontStyle="Normal" FontFamily="Segoe UI"/>
                </StackPanel>
            </DataTemplate>
        </phone:LongListSelector.ItemTemplate>
    </phone:LongListSelector>
</Grid>


现在我知道,如果我们不在XAML文件或属性中提及width、MaxWidth值,那么上面的Textblock会将自身拉伸到适合文本的宽度。如果还有更多的宽度,它将扩展到那个程度。但是我想包装Textblock的文本。同时,我想利用所有可用于拉伸文本块的宽度。因此,基本上我希望Textblock使用可用的最大宽度拉伸自身,如果其中的文本仍然较长,则我希望将其包装。是否有任何解决方案来实现这一点。我可以通过设置宽度的常量值来使用文本换行。因为我想在不同的模型上部署这个应用程序,那么我可以让它通用吗?是否还有使用父级宽度的方法?

您所要做的就是将
堆栈面板
替换为
网格

<DataTemplate>
    <Grid Margin="25,20" Background="#FF616464" Width="Auto">
        <TextBlock Text="{Binding title, Mode=TwoWay}" FontSize="40" Margin="20,20" Foreground="White" TextAlignment="Left" TextWrapping="Wrap" FontStyle="Normal" FontFamily="Segoe UI"/>
    </Grid>
</DataTemplate>

结果:

尝试此属性
HorizontalContentAlignment=“Stretch”

Rejman网格对Stackpanel超高有何作用。当我们将宽度称为“自动”时,它会根据内容长度自行调整。那么网格是如何工作的呢?哪一个最适合用于LongListSelector?Stackpanel或Grid?Grid将内容拉伸到其边界。StackPanel可以永远成长。谢谢,这就是我需要的区别。