Inline object in TextBlock with TextTrimming = CharacterEllipsis or WordEllipsis
Asked Answered
K

2

11

If you run this code and minimize/maximize width of the window

<TextBlock TextTrimming="WordEllipsis" >
    <Run Text="I want that this rectangle will be placed "/>
    <Rectangle Fill="Black" Width="20" Height="10" />
    <Run Text=" here when I minimize width of the window"/>
</TextBlock>

you will see what Rectange will shift to the left side. enter image description here enter image description here

Is a bug in the WPF?

Kristankriste answered 6/9, 2012 at 11:33 Comment(1)
I did not find anything in the WPF documentation that mentions that InlineUIContainers (such as Rectangles) are exempt from text trimming. Therefore I think it is either a bug in the WPF implementation or an omission in the WPF documentation. I suggest you create a bug report on Microsoft Connect.Katherinkatherina
F
0

I guess this is not a bug. Try to take TextTrimming="WordEllipsis" property off the text block (it affects the whole control) and you will see that the rectangle wont move with you window size changes beacause you dont have any HorizentalAligment properties.

Fruge answered 10/3, 2015 at 8:40 Comment(0)
G
0

While it seems to be a bug, this might be a workaround:

<TextBlock TextTrimming="WordEllipsis" >
<Run Text="I want that this rectangle will be placed "/>
<Run Text="&#x25A0;" FontSize="40" BaselineAlignment="Center"/>
<Run Text=" here when I minimize width of the window"/>
</TextBlock>

See Unicode Characters in the Geometric Shapes Block.

Georama answered 18/2, 2017 at 11:25 Comment(1)
Note that I tried to solve it by putting three TextBlock, one after each other in a DockPanel, but the result was not satisfying.Georama

© 2022 - 2024 — McMap. All rights reserved.