[英]HyperlinkButton inside Text Block
There is some text that i want to take from JSON file: 我想从JSON文件中提取一些文本:
"text":"evqvqgqegweg<br>wegewg<br>e<br>ewgewg<br>ewg<br>http:\/\/f.com<br>egewg"
How can I detect the link and parse it to the textblock with HyperlinkButton
? 如何使用
HyperlinkButton
检测链接并将其解析为文本块?
Thanks in advance! 提前致谢!
You can use a simple regular expression to pick out your links: http:.*[.com|.co.uk]
This will of course also parse any escape characters: http:\\/\\/f.com
. 您可以使用简单的正则表达式来选择链接:
http:.*[.com|.co.uk]
当然,这也将解析所有转义字符: http:\\/\\/f.com
。
You can use it like this: 您可以像这样使用它:
Match match = Regex.Match(inputTextString, "http:.*[.com|.co.uk]");
if (match.Success) PublicLinkProperty = new Uri(match.Value);
Where PublicLinkProperty
is a property on your view model/code behind: 其中,
PublicLinkProperty
是视图模型/代码后面的属性:
// you should implement the INotifyPropertyChanged interface on this property
public Uri PublicLinkProperty { get; set; }
You can then use that property to Bind
to the HyperlinkButton.NavigateUri
property: 然后,您可以使用该属性
Bind
到HyperlinkButton.NavigateUri
属性:
<HyperlinkButton Content="Click here" NavigateUri="{Binding PublicLinkProperty}"
TargetName="_blank" />
Note that this regular expression will pick out anything that starts with http:
and ends with either .com
or .co.uk
. 请注意,这个正则表达式会挑出任何开头
http:
与任一端.com
或.co.uk
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.