0

我正在为文本块设置不同的文本,具体取决于选择的控件作为为用户提供帮助的一种方式。

What I would like to do is in the code behind file, when one control is selected, provide a brief explanation in text, then provide a link to a text file within that textblock.

例如,它可能看起来像“您的选择应该是汽车制造商。单击此处查看列表”

我试图用超链接来做,但我运气不好。

有人知道该怎么做吗?

4

1 回答 1

4

使用 TextBlock.Inlines 集合并添加一个超链接:

XAML:

<TextBlock Name="hintInfo" />

代码:

Hyperlink hlink = new Hyperlink(new Run("here"));
hlink.Click += SomeEventHandler;  // event handler to open text file

hintInfo.Inlines.Clear();
hintInfo.Inlines.Add("Click ");
hintInfo.Inlines.Add(hlink);
hintInfo.Inlines.Add(" to see more info.");

要显示文本文件,您可以使用 Process.Start 启动外部查看器(例如记事本),或者您可以使用 File.ReadAllText 将其读入,然后将其显示在 TextBlock 或应用程序中的任何内容中。

于 2010-01-19T00:56:40.093 回答