2017-06-06 13 views
0

私の目標は、新しいウィンドウを開くリンクを持つ文字列を持つことです。キャッチは、文字列がローカライズ可能でなければならないということです。リソース文字列の一部のみをxamlのリンクにします。

私たちのローカリゼーションツールは、文字列を認識することができるようにするためには、それは次のように定義する必要があります。

<sys:String x:Uid="testString" x:Key="testString">click here for a good time</sys:String> 

文字列は次のように参照することになります。

<TextBlock Text="{StaticResource testString}"/> 

I別のウィンドウを開くリンクにするには、「ここ」という言葉が必要です。他の言葉はクリックしても何もしません。

これも可能ですか?

答えて

0

これらの文字列を分割できない理由はありますか?あなたの質問では、「ここ」がクリックすべき場所に翻訳されているとみなしています。

<sys:String x:Uid="prefix" x:Key="testString">click</sys:String> 
<sys:String x:Uid="caption" x:Key="testString">here</sys:String> 
<sys:String x:Uid="suffix" x:Key="testString">for a good time</sys:String> 

<StackPanel> 
    <TextBlock Text="{StaticResource prefix}" /> 
    <Button Command={StaticResource someCommand}> 
     <TextBlock Text="{StaticResource caption}" /> 
    </Button> 
    <TextBlock Text="{StaticResource suffix}" /> 
</StackPanel> 
0

これはさえ可能ですか?

stringを何らかの形で単語に分割せずにコードを書く必要はありません。あなたはどこかで実際のリンクを定義する必要があります。

たとえば、TextBlockLoadedイベントを処理し、そのInlineプロパティに値を設定できます。

ここに、あなたにその考えを示す例があります。私が恐れていたものです

<TextBlock Text="{StaticResource testString}" Loaded="TextBlock_Loaded"/> 

private void TextBlock_Loaded(object sender, RoutedEventArgs e) 
{ 
    const string linkText = "here"; 
    TextBlock txt = sender as TextBlock; 
    string[] words = txt.Text.Split(' '); 
    if (words.Contains(linkText)) 
    { 
     txt.Text = string.Empty; 
     foreach (string word in words) 
     { 
      if (word == linkText) 
      { 
       var link = new Hyperlink(new Run(linkText + " ")); 
       link.Click += (ss, ee) => 
       { 
        //do something when the link is clicked on 
       }; 
       txt.Inlines.Add(link); 
      } 
      else 
      { 
       txt.Inlines.Add(word + " "); 
      } 
     } 
     txt.Text.TrimEnd(); 
    } 
} 
+0

。 文字列を分割することはできません。「ここをクリックして楽しい時間を過ごしてください。 – Ash

+0

「here」という単語をクリック可能と定義するところは...? – mm8

関連する問題