문제

I've got this really weird problem where I'm doing highlighting on certain parts of text on a TextBlock object containing multiple Run objects.

    <TextBlock Name="InlineTextBlock" Background="White">

            <Run Foreground="White"
                 Background="Blue"
                 FontSize="75"
                 FontFamily="Helvetica">17-Oct-13</Run>

            <Run Foreground="White"
                 Background="Blue"
                 FontSize="75"
                 FontFamily="Helvetica">17/Oct/13</Run>
    </TextBlock>

It's pretty straightforward code to read, and from reading, you would expect both 17-Oct-13 and 17/Oct/13 to be completely highlighted with a Blue Background and White Foreground.

The odd thing is, the hyphen character has 1 pixel on the left and the right where the Background color is not being applied.

There are no issues with highlighting for the second Run object with 17/Oct/13.

Would appreciate any help to figure out this odd problem.

EDIT: Running this on my computer displays the following (you'll have to look really closely to see it): White lines around the hyphens

Also, I noticed this only occurs on certain fonts like Helvetica, Arial, Consolas (to name a few). Verdana seems to display fine.

도움이 되었습니까?

해결책

Unfortunately, running your code on my computer does not suffer from this problem:

enter image description here

I'm guessing that you have something else causing your problem.

For your information, I'm running Visual Studio 2010 on Windows 7 and .NET 4.0.


UPDATE >>>

Thanks for the update... I can now confirm that I see your mysterious vertical white lines around the hyphens using the Helvetica font. I can't imagine what is causing it, but assuming that you can't set the main TextBlock.Background to Blue, you can still fix this issue by using an inner TextBlock with its Background set to Blue:

<TextBlock Name="InlineTextBlock" Background="White">
    <TextBlock Background="Blue">
        <Run Foreground="White"
                Background="Blue"
                FontSize="50"
                FontFamily="Helvetica">17-Oct-13</Run>

        <Run Foreground="White"
                Background="Blue"
                FontSize="50"
                FontFamily="Helvetica">17/Oct/13</Run>
    </TextBlock>
</TextBlock>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top