[英]xaml TextBlock to show text with partial bold font
我將從我的數據庫中獲取一個字符串並將其中的一部分(例如匹配關鍵字)設置為粗體。 然后將其顯示在 TextBlock 上。 例如,“嗨,湯姆是誰?我需要找到他。”
我參考這個鏈接: https://social.msdn.microsoft.com/Forums/en-US/bb1f558c-a2dd-4977-85d7-8e0ce9631681/how-to-make-part-of-a-string-bold- in-c?forum=aspgettingstarted將匹配的單詞翻譯成粗體:
private string FormatString(string wholeString, string boldPart)
{
return Regex.Replace(wholeString, boldPart, @"<b>$0</b>", RegexOptions.IgnoreCase);
}
然后我得到這個格式化的新字符串“嗨,誰是 <b>Tom</b>?我需要找到他。”
您可以在多個Run
中拆分文本,並將FontWeight
用於粗體文本。
<TextBlock>
<Run Text="Who is "/>
<Run FontWeight="Bold" Text="Tom"/>
<Run Text="? I need to find him!"/>
</TextBlock>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.