简体   繁体   English

具有链接到文本文件的文本块

[英]Textblock with link to text file inside

I am setting different text to a textblock depending on what control has been selected as a way of providing help for the user. 我将根据已选择哪种控件为用户提供帮助的方式,将不同的文本设置为文本块。

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. 我想做的是在文件后面的代码中,选择一个控件后,在文本中进行简要说明,然后在该文本块中提供指向文本文件的链接。

It might look like, for example "Your choice should be a car manufacturer. Click here to see a list" 例如,“您的选择应该是汽车制造商。请单击此处查看列表”。

I was trying to do it with a hyperlink but i'm not having much luck. 我试图用超链接来做,但是我运气不好。

Anyone know how to do it? 有人知道怎么做吗?

Use the TextBlock.Inlines collection and add a Hyperlink: 使用TextBlock.Inlines集合并添加一个超链接:

XAML: XAML:

<TextBlock Name="hintInfo" />

Code: 码:

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.");

To display the text file, you could use Process.Start to launch an external viewer (eg Notepad), or you could use File.ReadAllText to read it in, and then display it in a TextBlock or whatever within your app. 要显示文本文件,可以使用Process.Start启动外部查看器(例如记事本),也可以使用File.ReadAllText读取它,然后在TextBlock或应用程序中的任何内容中显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM