Search code examples
xamlwindows-phone-8.1globalization

RichTextBlock, Paragraph, Hyperlink... and globalization


In Windows Phone 8.1 you can use different languages useing the property "x:Uid" of an element, if I do

<textblock x:Uid="string1"/>

and in a resource file I write

string1.Text: sentence in english

then "sentence in english" "is written" in the Text property of the textblock. For buttons would be string1.Content.

But I have a problem, I am using RichTextBlock, with a Paragraph and Hyperlink inside, I can use x:Uid but... which property to use? They don't have Text or Content property, so... how can I globalizate that elements?

Thank you.


Solution

  • The Paragraph and Hyperlink are collections. The actual text comes from a Run somewhere inside, and the Run has a Text property. If you set the run explicitly instead of implicitly then you can add x:Uid to its Text property:

    Xaml:

    <Hyperlink>
        <Run x:Uid="hlink" Text="http://microsoft.com" />
    </Hyperlink>
    

    Resources.resw:

    <data name="hlink.Text" xml:space="preserve">
        <value>http://stackoverflow.com</value>
    </data>
    

    The displayed Hyperlink will pull the stackoverflow URL from the resource file.