我在下面的例子中一直试图用粗体和斜体字来表示一些字符串,但它不起作用。是否可以编辑字符串的格式?
private TestQuickInfoSourceProvider m_provider;
private ITextBuffer m_subjectBuffer;
private Dictionary<string, string> m_dictionary;
public TestQuickInfoSource(TestQuickInfoSourceProvider provider, ITextBuffer subjectBuffer)
{
m_provider = provider;
m_subjectBuffer = subjectBuffer;
//Methods and their description, good for unique keywords AKA QuickInfo words
m_dictionary = new Dictionary<string, string>();
m_dictionary.Add("adapt", "<b> Process given file </b>\n"
这是输出 http://i.stack.imgur.com/smDUF.png
格式化字符串的正确方法是什么?
修改///
通过CSV找到一种更简单的方法来处理大量数据。
答案 0 :(得分:1)
您的代码的基本部分(未包含在您的帖子中)是 AugmentQuickInfoSession 方法的实现。我假设您目前只是从m_dictionary
那里返回字符串值。
在QuickInfo中获取格式化结果需要更多工作。我们来看看AugmentQuickInfoSession:
的定义void AugmentQuickInfoSession(IQuickInfoSession existingQuickInfoSession, IList<object> quickInfoContent, out ITrackin)
quickInfoContent
是对象的列表。如果您返回String
,则不会格式化。但是,如果您返回TextBlock
对象,则可以包含格式化文本。
示例代码:
var textBlock = new TextBlock { TextWrapping = TextWrapping.NoWrap };
var boldRun = new Run("This is a bit of bold text.");
boldRun.FontWeight = FontWeights.Bold;
textBlock.Inlines.Add(boldRun);
var normalRun = new Run("This is not very bold.);
textBlock.Inlines.Add(normalRun );
...
quickInfoContent.Add(textBlock);