StackPanel 中的文本不换行 (wp7)
我的文本换行有问题。如果没有 StackPanel,这个 TextBlock 可以工作,但我需要在文本之前放置小图片。另外,我没有两列(前三行我只需要一列)
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions >
<RowDefinition Height="60"/>
<RowDefinition Height="170"/>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"></TextBlock>
<TextBlock Grid.Row="1"></TextBlock>
<TextBlock Grid.Row="2"></TextBlock>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Image Source="Picture.png" MaxHeight="20" MaxWidth="40" HorizontalAlignment="Center" Margin="0,20,0,0" />
<TextBlock Text="Long long long text from Binding" FontSize="25" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Bottom" Padding="20,10,0,0" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
I have problem with text wrapping. Without StackPanel this TextBlock works, but i need to put small picture before text. Also I don't have two columns for this (i need only one column for first three rows)
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions >
<RowDefinition Height="60"/>
<RowDefinition Height="170"/>
<RowDefinition Height="50"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"></TextBlock>
<TextBlock Grid.Row="1"></TextBlock>
<TextBlock Grid.Row="2"></TextBlock>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Image Source="Picture.png" MaxHeight="20" MaxWidth="40" HorizontalAlignment="Center" Margin="0,20,0,0" />
<TextBlock Text="Long long long text from Binding" FontSize="25" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Bottom" Padding="20,10,0,0" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
StackPanel 将根据
Orientation
为其组件提供无限的高度或宽度。如果我查看您的 XAML,我建议在网格中使用两列,并将图像放在左侧:
注意第一个文本框上的 Grid.ColumnSpan,这会将它们跨越网格的整个宽度,而不仅仅是网格的宽度第一栏。
A
StackPanel
will give its components infinite height or width depending on theOrientation
.If I look at your XAML I would suggest to use two columns in the grid, and put the image on the left side:
Notice Grid.ColumnSpan on the first textboxes, this will span them over the entire width of the grid, not just the first column.