1: string linkLabelText = this.Text;
2: string preUri = string.Empty;
3: string[] preUriWords = null;
4: string postUri = string.Empty;
5: string[] postUriWords = null;
6: int startIndexOfUri = 0;
7: char[] delimiter = { ' ' };
8:
9: // no uris found
10: if ( links == null || links.Count == 0 )
11: {
12: this.layoutRoot.Children.Add( new TextBlock()
13: {
14: Text = this.Text,
15: Style = this.TextStyle
16: } );
17: return;
18: }
19:
20: foreach ( Link link in links )
21: {
22: startIndexOfUri = linkLabelText.IndexOf( link.Key, StringComparison.OrdinalIgnoreCase );
23: preUri = linkLabelText.Substring( 0, startIndexOfUri );
24: postUri = linkLabelText.Substring( preUri.Length + link.Key.Length );
25: linkLabelText = postUri;
26:
27: // put all the words before the current Uri
28: preUriWords = preUri.Split( delimiter, StringSplitOptions.RemoveEmptyEntries );
29: foreach ( string preWord in preUriWords )
30: {
31: this.layoutRoot.Children.Add( new TextBlock()
32: {
33: Text = preWord + " ",
34: Style = this.TextStyle
35: } );
36: }
37:
38: // insert the Uri
39: HyperlinkButton hyperlink = new HyperlinkButton()
40: {
41: Content = link.Text + " ",
42: NavigateUri = link.NavigateUri,
43: TargetName = link.TargetName,
44: Style = this.LinkStyle
45: };
46: hyperlink.Click += new RoutedEventHandler( this.ClickLink );
47: this.layoutRoot.Children.Add( hyperlink );
48: }
49:
50: // append the text after the last uri found
51: if ( !string.IsNullOrEmpty( linkLabelText ) )
52: {
53: postUriWords = postUri.Split( delimiter, StringSplitOptions.RemoveEmptyEntries );
54: foreach ( string postWord in postUriWords )
55: {
56: this.layoutRoot.Children.Add( new TextBlock()
57: {
58: Text = postWord + " ",
59: Style = this.TextStyle
60: } );
61: }
62: }