2012-01-12 20 views
2

我有這樣一個TextBlock:我可以使用TextBlock TextTrimming只修剪第一次運行,而不是整個事情?

<TextBlock TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxHeight="50"> 
    <TextBlock.Inlines> 
     <Run Text="Some text that might be long so I want it wordwrapped." /> 
     <Run Text="Link" /> 
    </TextBlock.Inlines> 
    </TextBlock> 

第二輪被格式化像一個超鏈接。不幸的是,當第一次運行足夠強迫省略號時,Link會被切斷。我想要發生的是這樣的:

Some text that might 
be long so I... Link 

可以這樣做嗎?

回答

2

將TextTrimming設置爲CharacterEllipsis我假設您希望它切斷太長的一條線。

例)

<TextBlock.Inlines> 
    <Run Text="Some text that might be long so I want it wordwrapped." /> 
    <Run Text="Link" /> 
</TextBlock.Inlines> 

應顯示
「一些文字,可能會很長......」
「鏈接」

<TextBlock TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" MaxHeight="50"> 
    <TextBlock.Inlines> 
     <Run Text="Some text that might be long so I want it wordwrapped." /> 
     <Run Text="Link" /> 
    </TextBlock.Inlines> 
</TextBlock> 

如果這是你想實現什麼,然後只需刪除TextWrapping =「Wrap」

這裏有幾件事要看一看at:

是否必須是one TextBlock? 如果沒有,你可以做以下...

<WrapPanel> 
    <TextBlock Text="Some text that might be long so I want it wordwrapped. " TextWrapping="Wrap"/> 
    <TextBlock TextWrapping="Wrap"> 
     <Hyperlink NavigateUri="http://www.stackoverflow.com">Link</Hyperlink> 
    </TextBlock> 
</WrapPanel> 

是否必須是一個TextBlock的? 如果沒有,你可以做以下...

<RichTextBox IsReadOnly="True" Background="Transparent" BorderThickness="0" BorderBrush="Transparent"> 
<FlowDocument> 
    <Paragraph> 
     Some text that might be long so I want it wordwrapped. 
     <Hyperlink NavigateUri="http://www.stackoverflow.com">Link</Hyperlink> . 
    </Paragraph> 
</FlowDocument> 

是任何幫助,這些解決方案?

+0

這不是我想要實現的。我希望鏈接在文本之後,而不是在下面。我希望文本被包裝,因爲我的水平空間有限。 – 2012-01-12 02:22:26

+0

對不起,這些似乎沒有做我想要的。我想要的是文本被包裝和修剪,如果有必要,但鏈接出現在省略號後的最後一行。 – 2012-01-12 04:37:18

+0

我很抱歉地說,但我敢肯定你*不能*做到這一點,而不創建自己的自定義TextBlock繼承自TextBlock(和一些騙局) – MyKuLLSKI 2012-01-12 06:13:50

相關問題