0
有一些文字,我想從JSON文件採取:HyperlinkButton內文本塊
"text":"evqvqgqegweg<br>wegewg<br>e<br>ewgewg<br>ewg<br>http:\/\/f.com<br>egewg"
我怎樣才能檢測到鏈路,並將其與HyperlinkButton
解析的文本塊?
提前感謝!
有一些文字,我想從JSON文件採取:HyperlinkButton內文本塊
"text":"evqvqgqegweg<br>wegewg<br>e<br>ewgewg<br>ewg<br>http:\/\/f.com<br>egewg"
我怎樣才能檢測到鏈路,並將其與HyperlinkButton
解析的文本塊?
提前感謝!
您可以使用一個簡單的正則表達式來挑選出您的鏈接:http:.*[.com|.co.uk]
這當然也會解析任何轉義字符:http:\/\/f.com
。
您可以使用它像這樣:
Match match = Regex.Match(inputTextString, "http:.*[.com|.co.uk]");
if (match.Success) PublicLinkProperty = new Uri(match.Value);
凡PublicLinkProperty
是您的視圖模型/代碼後面的屬性:
// you should implement the INotifyPropertyChanged interface on this property
public Uri PublicLinkProperty { get; set; }
然後,您可以使用該財產Bind
到HyperlinkButton.NavigateUri
財產:
<HyperlinkButton Content="Click here" NavigateUri="{Binding PublicLinkProperty}"
TargetName="_blank" />
注意t這個正則表達式將會挑選出任何東西,以http:
開頭並以.com
或.co.uk
結束。
看看[我的答案](http://stackoverflow.com/questions/19066725/wpf-listbox-with-file-hyperlink-mvvm/19071322#19071322) –