WPF 文本块在 Windows 7 上截断多行
我正在使用文本块在产品图像下显示产品描述。文本宽度必须固定为 100 像素,但高度可以增加到 30 像素高。如果文本仍然无法容纳,则必须显示省略号。这是我的 xaml:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" .../>
<Canvas/>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="{Binding Path=ProductDescription}"
HorizontalAlignment="Center" VerticalAlignment="Top" TextAlignment="Center">
</StackPanel>
描述可以有多行。例如,“无线鼠标\n数量:20”。在 XP 上看起来没问题,但在 Windows 7 上只显示第一行并且没有省略号。谁能发现我的 xaml 中的问题吗?
I am using a textblock to display the product description under the product's image. The text must be fixed 100px wide but the height can grow up to 30px tall. If the text still can't fit, it must display ellipsis. Here is my xaml:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" .../>
<Canvas/>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="{Binding Path=ProductDescription}"
HorizontalAlignment="Center" VerticalAlignment="Top" TextAlignment="Center">
</StackPanel>
The description can have multiple lines. For eg, "Wireless Mouse\nQuantity:20". It looks ok on XP but on Windows 7 only the first line shows up and there's no ellipsis. Can anyone spot the problem in my xaml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的示例中有几个错误: should 、“.../>”不是有效的 XAML,并且您的 TextBlock 没有结束标记。
以下 XAML 在 Windows 7 上运行良好:
There are several errors in your example: should , ".../>" isn't valid XAML and your TextBlock doesn't have a closing tag.
The follow XAML worked fine on for me on Windows 7:
根据字体大小,
MaxHeight
30 几乎只是一行文本,因此文本块的高度无法增长。更改它或完全删除它。Depending on the font size
MaxHeight
of 30 is almost just one line of text, so the textblock can't grow in height. Change it or remove it completely.