Created
November 12, 2012 13:46
-
-
Save misodengaku/4059480 to your computer and use it in GitHub Desktop.
WP7でHyperlink混じりのTextBlockみたいなアレ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void button1_Click(object sender, RoutedEventArgs e) | |
{ | |
string sample = "トトリちゃんかわいい http://totori.dip.jp @misodengaku "; | |
var f = sample.Split(new char[] { ' '}); | |
var para = new Paragraph(); | |
foreach (var item in f) | |
{ | |
if (item.StartsWith("http")) //Webページ開く(判定雑すぎ) | |
{ | |
var link = new Hyperlink(); //Hyperlinkオブジェクト作成 | |
link.Inlines.Add(item); // | |
link.TargetName = "_blank"; //ブラウザで開くのに必要 | |
link.NavigateUri = new Uri(item); //ナビゲーション先Uri設定 | |
para.Inlines.Add(link); //Block追加 | |
} | |
else if (item.StartsWith("@")) //Twitterユーザーページ開く | |
{ | |
item.TrimStart(new char[] { '@' }); | |
var link = new Hyperlink(); | |
link.Inlines.Add(item); | |
link.TargetName = "_blank"; | |
link.NavigateUri = new Uri("http://twitter.com/" + item); | |
para.Inlines.Add(link); | |
} | |
else //それ以外(==ただの文字列) | |
{ | |
para.Inlines.Add(item); | |
} | |
para.Inlines.Add(" "); //空白で区切る | |
} | |
//var text = new Hyperlink(); | |
//text.Inlines.Add("トトリちゃん"); | |
richTextBox1.Blocks.Add(para); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment