WPF TextBlock Padding 正在剪切文本
我在 Grid
中有一个 TextBlock
,其 Padding
属性设置为 5。有时最后一个字符会被截断,具体取决于 的字符串code>Text
属性设置为。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SomeClass">
<ScrollViewer Padding="5" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label
Grid.Row="0" Grid.Column="0"
Content="SomeLabel"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
VerticalAlignment="Center" />
<TextBlock
Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Left"
Padding="5"
Text="0x0F"
TextWrapping="Wrap"
VerticalAlignment="Top" />
</Grid>
</ScrollViewer>
</UserControl>
当Text
设置为0x0F
时,F
不可见。当它设置为 0xAB 时,字符串显示得很好。将 Padding
设置为 0 也可以使字符串显示得很好。
I have a TextBlock
in a Grid
with its Padding
attribute set to 5. Sometimes the last character is cut off, depending on what string the Text
property is set to.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SomeClass">
<ScrollViewer Padding="5" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label
Grid.Row="0" Grid.Column="0"
Content="SomeLabel"
HorizontalAlignment="Right"
HorizontalContentAlignment="Right"
VerticalAlignment="Center" />
<TextBlock
Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Left"
Padding="5"
Text="0x0F"
TextWrapping="Wrap"
VerticalAlignment="Top" />
</Grid>
</ScrollViewer>
</UserControl>
When the Text
is set to 0x0F
the F
is not visible. When it is set to 0xAB
the string displays just fine. Setting the Padding
to 0 also makes the string display just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您所描述的显然是 WPF 中的布局错误(可能在 TextBlock 中)。最后一个字母是否被换行(和切断)似乎取决于字符串的实际宽度以及最后一个字母相对于填充大小的大小。
我建议您报告该错误这里。
要解决此问题,您可以使用以下代码(只需在文本块周围放置边框并在那里设置填充):
What you describe is obviously a layout bug in WPF (probably in the TextBlock). Whether or not the last letter is wrapped (and cut off) seems to depends on the actual width of the string and the size of the last letter in respect to the size of the padding.
I suggest you report the bug here.
To work around this issue you can use the following code (just put a border around you textblock and set the padding there instead):
使包含文本块自动调整大小的网格列像这样
Make the column of the grid that contains textblock auto size like this
如果将 TextBlock 的高度设置为 100,F 是否会被换行?
If you set the height on the TextBlock to 100, does the F then get wrapped?
只需增加 ComboBoxItem 的高度,就可以解决问题。
Just increase the Height of the ComboBoxItem , it should solve the problem.