2013-10-17 59 views
0

有一些文字,我想從JSON文件採取:HyperlinkBut​​ton內文本塊

"text":"evqvqgqegweg<br>wegewg<br>e<br>ewgewg<br>ewg<br>http:\/\/f.com<br>egewg" 

我怎樣才能檢測到鏈路,並將其與HyperlinkButton解析的文本塊?

enter image description here

提前感謝!

+0

看看[我的答案](http://stackoverflow.com/questions/19066725/wpf-listbox-with-file-hyperlink-mvvm/19071322#19071322) –

回答

1

您可以使用一個簡單的正則表達式來挑選出您的鏈接: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; } 

然後,您可以使用該財產BindHyperlinkButton.NavigateUri財產:

<HyperlinkButton Content="Click here" NavigateUri="{Binding PublicLinkProperty}" 
    TargetName="_blank" /> 

注意t這個正則表達式將會挑選出任何東西,以http:開頭並以.com.co.uk結束。

相關問題