粗体,内联,文本块的超链接集合?
获取代码:
results.senselist += "\n" + sense_list + Orth + gramGroup + "\n";
我希望gramGroup是超链接,其他颜色和sense_list是粗体或内联。
希望All in code。
您需要根据需要在xaml中定义Inlines并绑定propeties。
DataContext
可以是
public class MyDataContext { public MyDataContext() { PlainText1 = "This is"; LinkText = "some link"; PlainText2 = "with text"; ColorText = "and red color :)"; } public string LinkText { get; set; } public string ColorText { get; set; } public string PlainText1{ get; set; } public string PlainText2 { get; set; } }
在屏幕上呈现如下
我错过了问题中的大胆部分。 只需在TextBlock
中设置FontWeight="Bold"
。
不可能为同一文本的不同部分设置样式。 您应该使用两个不同的TextBlock:
gramGroup
您可以使用标签,因为它是内容控件,您可以编写一个转换器,将字符串转换为具有所有格式的文本块。 我假设在两个字符串之间有一个分隔符来区分它们。 请参阅以下代码。
class TextBlockConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { TextBlock txt = new TextBlock(); string str = (string)value; string[] strList = str.Split('|'); Run run1 = new Run(strList[0]); run1.FontWeight = FontWeights.Bold; Run run2 = new Run(strList[1]); Hyperlink hyp = new Hyperlink(run2); txt.Inlines.Add(run1); txt.Inlines.Add(hyp); return txt; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } senselist = "sense_list" + "|" + "gramGroup";