There are pictures of what I want to achieve in this question.
I tried putting the TextBlock and the Button in a WrapPanel, and this works for single-line text but not for multi-line text.
<WrapPanel>
<TextBlock
TextTrimming="WordEllipsis"
TextWrapping="WrapWithOverflow" .../>
<Button .../>
</WrapPanel>
The picture below shows what's happening. When the TextBlock text becomes 2 lines the second line takes the whole width of the first line, which is logical.

I thought of chopping the string by words and using an ItemsControl with WrapPanel as ItemsPanel. But the text may become longer, and there isn't space for more than 2 lines, that's why I put the TextTrimming="WordEllipsis" there; the remaining text will be trimmed and the button will be at the end of the second line, in that case.
Update: Well it turned out to be not so easy, I went with changing my UI to something simpler like putting a rounded button on the right.