1Public Class Person
2 Public Property Name As String
3 Public Property Description As String
4End Class
56Public Property Persons As New List(Of Person)
78Public Sub New()
9Persons.Add(New Person() With { .Name="織田信長", .Description="織田信長は、(注%織田弾正忠家の当主%)・(注%織田信秀の子%)に生まれ、・・・"})
10Persons.Add(New Person() With { .Name="豊臣秀吉", .Description="初め(注%木下氏%)で、後に(注%羽柴氏%)に改める。・・・"})
11End Sub
1/// <summary>2/// HyperLinkEx.xaml の相互作用ロジック3/// </summary>4public partial class HyperLinkEx : UserControl
5{6/// <summary>7/// Descriptiontとして表示する文字列8/// </summary>9 public string TextContent
10{11 get {return(string)GetValue(TextContentProperty);}12 set {SetValue(TextContentProperty, value);}13}14 public static readonly DependencyProperty TextContentProperty =15 DependencyProperty.Register("TextContent",typeof(string),typeof(HyperLinkEx), new PropertyMetadata(null,(v1,v2)=>16{17(v1 as HyperLinkEx)?.UpdateContents();18}));192021/// <summary>22/// 特定文字クリック時に発火するコマンド23/// </summary>24 public ICommand LinkCommand
25{26 get {return(ICommand )GetValue(LinkCommandProperty);}27 set {SetValue(LinkCommandProperty, value);}28}29 public static readonly DependencyProperty LinkCommandProperty =30 DependencyProperty.Register("LinkCommand",typeof(ICommand ),typeof(HyperLinkEx), new PropertyMetadata(null,(v1,v2)=>31{32(v1 as HyperLinkEx)?.UpdateContents();33}));3435 public HyperLinkEx()36{37InitializeComponent();38}3940voidUpdateContents()41{42 this._Content.Inlines.Clear();43if(string.IsNullOrEmpty(this.TextContent)== true || LinkCommand == null)44return;4546//特定文字用パターン文字列47 var pattern = @"(\%.+?\%)";4849//特定文字とそれ以外に分割50 var items = Regex.Split(TextContent, pattern);5152foreach( var item in items )53{54//特定文字ならHyperLink55if( Regex.Match(item, pattern).Success)56{57 var hyperlink = new Hyperlink(new Run(item.Replace("%","")))58{59 Command = LinkCommand,60 CommandParameter = item
61};62 _Content.Inlines.Add(hyperlink);63}64else65{66 _Content.Inlines.Add(new Run(item));67}68}69}70}