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.
我在Grid中有一个TextBlock,其Padding属性设置为5.有时最后一个字符被截断,具体取决于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>
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.
当Text设置为0x0F时,F不可见。当它设置为0xAB时,字符串显示就好了。将填充设置为0也使字符串显示正常。
4 个解决方案
#1
6
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.
您描述的内容显然是WPF中的布局错误(可能在TextBlock中)。最后一个字母是否被包装(和切断)似乎取决于字符串的实际宽度和最后一个字母相对于填充大小的大小。
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):
要解决此问题,您可以使用以下代码(只需在文本块周围添加边框并在其中设置填充):
<Border Padding="5" Grid.Row="0" Grid.Column="1">
<TextBlock HorizontalAlignment="Left"
Text="0x0F" TextWrapping="Wrap"
VerticalAlignment="Top" />
</Border>
#2
0
Make the column of the grid that contains textblock auto size like this
使包含文本块自动大小的网格列成为这样
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.COlumn="0" Text="{Binding Path=SomeViewModelProperty}" />
</Grid>
#3
0
If you set the height on the TextBlock to 100, does the F then get wrapped?
如果你将TextBlock的高度设置为100,那么F会被包裹吗?
#4
0
Just increase the Height of the ComboBoxItem , it should solve the problem.
只需增加ComboBoxItem的高度,就应该解决问题。
#1
6
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.
您描述的内容显然是WPF中的布局错误(可能在TextBlock中)。最后一个字母是否被包装(和切断)似乎取决于字符串的实际宽度和最后一个字母相对于填充大小的大小。
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):
要解决此问题,您可以使用以下代码(只需在文本块周围添加边框并在其中设置填充):
<Border Padding="5" Grid.Row="0" Grid.Column="1">
<TextBlock HorizontalAlignment="Left"
Text="0x0F" TextWrapping="Wrap"
VerticalAlignment="Top" />
</Border>
#2
0
Make the column of the grid that contains textblock auto size like this
使包含文本块自动大小的网格列成为这样
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.COlumn="0" Text="{Binding Path=SomeViewModelProperty}" />
</Grid>
#3
0
If you set the height on the TextBlock to 100, does the F then get wrapped?
如果你将TextBlock的高度设置为100,那么F会被包裹吗?
#4
0
Just increase the Height of the ComboBoxItem , it should solve the problem.
只需增加ComboBoxItem的高度,就应该解决问题。