我正在使用单行网格 . 我在该行中放置了一个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文件或属性中的宽度,MaxWidth值,上面的Textblock会将自身拉伸到它真正需要适合文本的宽度 . 如果仍然有更多的宽度,它将扩展到那个程度 . 但是我想要包装Textblock的文本 . 同时我想利用所有可用的宽度来拉伸TextBlock . 所以基本上我希望Textblock使用可用的最大宽度来拉伸自身,如果其中的Text仍然更长,那么我想要包装它 . 有没有解决方案来实现这一目标 . 我可以通过设置宽度的常量值来使用文本换行 . 由于我想在不同的模型上部署这个应用程序,那么我可以将其设为通用吗?无论如何使用父母的宽度?
2 回答
您所要做的就是用
Grid
替换StackPanel
.结果:
试试这个属性HorizontalContentAlignment =“Stretch”