0
votes

in a WPF application I load news from an RSS feed. The contents are displayed in a TextBlock. This TextBlock has a certain size. Contents are cut off by the TextTrimming method. Now I would like at the end of each TextBlock to insert a hyperlink button. The only problem is I do not know exactly what position will be cut on my string. Is there a way to figure this out?

When I insert my Text in my TextBlock and then my Hyperlink-Button, my HyperlinkButton will be cut of. Can I prevent to cutt off my HyperlinkButton?

XAML-Code:

<TextBlock Name="myText" />

C#-Code:

Hyperlink hlink = new Hyperlink(new Run("here"));

myText.Inlines.Clear();
myText.Inlines.Add(value); //description from RSS Feed
myText.Inlines.Add(hlink);
2

2 Answers

1
votes

Why not just add the HyperLink after the text, by replacing both items in a StackPanel?

0
votes

If I understood your requirements this is one way to achieve your goals:

<StackPanel>  
    <DockPanel Width="200">
        <TextBlock DockPanel.Dock="Left"  Text="A short description."  TextTrimming="CharacterEllipsis"/>
        <TextBlock DockPanel.Dock="Right" TextAlignment="Right">
            <Hyperlink NavigateUri="http://www.google.com">here</Hyperlink>   
        </TextBlock>
    </DockPanel>
    <DockPanel Width="200">
        <TextBlock DockPanel.Dock="Left" TextTrimming="CharacterEllipsis" MaxWidth="170" Text="A really long descripion of the item." />
        <TextBlock DockPanel.Dock="Right" TextAlignment="Right">
            <Hyperlink NavigateUri="http://www.google.com">here</Hyperlink>   
        </TextBlock>
    </DockPanel>
</StackPanel>

enter image description here

So the DockPanel control might be a good candidate to consider.