2
votes

The problem I have with TextBlock is that it sometimes cuts off text. The image below is the output of the xaml below it. The first TextBlock should contain Défi maximum, but the last m is cut off. I get it to reappear when I change part of the style, but I need it to be exactly like this. What could be the cause of this?

As you can see the TextBlock has enough space, the margin around the TextBlock is blue in the image below. The second TextBlock has an extra character which causes the TextBlock to show the text correctly. (even though there is a spelling error in it ;-) )

Valid XHTML

<Window.Resources>
    <Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Candara"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="FontWeight" Value="Regular"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="Background" Value="Red"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="TextAlignment"  Value="Center"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Margin" Value="0"/>
    </Style>

    <Style TargetType="Grid">
        <Setter Property="Width" Value="87"/>
        <Setter Property="Height" Value="87"/>
        <Setter Property="Background" Value="Blue"/>
        <Setter Property="Margin" Value="1"/>
    </Style>
</Window.Resources>

<StackPanel Orientation="Horizontal">
    <Grid>
        <TextBlock>Défi maximum</TextBlock>
    </Grid>
    <Grid>
        <TextBlock>Défi maximume</TextBlock>
    </Grid>
    <Grid>
        <TextBlock>3x10</TextBlock>
    </Grid>
    <Grid>
        <TextBlock>4x10</TextBlock>
    </Grid>
</StackPanel>
1
You say: "I get it to reappear when I change part of the style". What change is that? - Daniel Hilgarth
When I set the Margin of TextBlock to 5 instead of the Padding. The problem is that I do not know the cause and that change may cause other texts to not display correctly. We have Korean texts for instance and it is hard to determine for me if some symbols are left out in hundreds of texts. - Wouter
Yes. I bumped into this the other day too.I ended up adding a xml:space="preserve" and adding a space to the end of the text, to work around the issue. For me it was chopping off the whole of the last word in a 3 word piece of text. Changing letters in the text or adding more made it appear - Peter Jeffery
This bug has been fixed, no longer reproducible in windows 10 with all patches applied. - Wouter

1 Answers

-1
votes

Decrease the font size or increase the box width.